Skip to content

Puppeteer (Chrome headless node API) based web page renderer with support for posting HTML

Notifications You must be signed in to change notification settings

sandord/puppeteer-renderer

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deploy to now

Puppeteer(Chrome headless node API) based web page renderer

Puppeteer (Chrome headless node API) based web page renderer.

Useful server side rendering through proxy. Outputs HTML, PDF and screenshots as PNG.

Updated with HTML string-based rendering, in addition to the already provided URL-based rendering.

Requirements

You can run Chromium or docker.

Getting Started

Install dependencies.

npm install

Start server (If you can run Chromium)

npm start

(service port: 3000)

Start server using docker (If you can not run Chromium and installed docker)

docker run -d --name renderer -p 8080:3000 zenato/puppeteer-renderer

Test on your browser

Input url http://localhost:{port}/?url=https://www.google.com

If you can see html code, server works fine.

Integration with existing service.

If you have active service, set proxy configuration with middleware. See puppeteer-renderer-middleware for express.

const renderer = require('puppeteer-renderer-middleware');

const app = express();

app.use(renderer({
  url: 'http://installed-your-puppeteer-renderer-url',
  // userAgentPattern: /My-Custom-Agent/i,
  // excludeUrlPattern: /*.html$/i
  // timeout: 30 * 1000,
}));

// your service logics..

app.listen(8080);

API

[GET] /

Render based on a URL.

Query string parameters:

Name Required Value Description Usage
url yes Target URL http://puppeteer-renderer?url=http://www.google.com
type pdf or screenshot Rendering another type. http://puppeteer-renderer?url=http://www.google.com&type=pdf
(Extra options) Extra options (see puppeteer API doc) http://puppeteer-renderer?url=http://www.google.com&type=pdf&scale=2

[POST] /

Render based on an HTML string.

Query string parameters:

Name Required Value Description Usage
type pdf or screenshot Rendering another type. http://puppeteer-renderer?url=http://www.google.com&type=pdf
(Extra options) Extra options (see puppeteer API doc) http://puppeteer-renderer?url=http://www.google.com&type=pdf&scale=2

Form fields:

Name Required Value Description Usage
html yes HTML string.
filename yes Filename without extension

PDF File Name Convention

Generated PDFs are returned with a Content-disposition header requesting the browser to download the file instead of showing it. The file name is generated from the URL rendered:

URL Filename
https://www.example.com/ www.example.com.pdf
https://www.example.com:80/ www.example.com.pdf
https://www.example.com/resource resource.pdf
https://www.example.com/resource.extension resource.pdf
https://www.example.com/path/ path.pdf
https://www.example.com/path/to/ pathto.pdf
https://www.example.com/path/to/resource resource.pdf
https://www.example.com/path/to/resource.ext resource.pdf

About

Puppeteer (Chrome headless node API) based web page renderer with support for posting HTML

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 98.5%
  • Dockerfile 1.5%