prm

puppeteer-renderer-middleware

Puppeteer(Chrome headless node API) based web page renderer

Showing:

Popularity

Downloads/wk

13

GitHub Stars

226

Maintenance

Last Commit

4d ago

Contributors

12

Package

Dependencies

1

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

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.

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

NameRequiredValueDescriptionUsage
urlyesTarget URLhttp://puppeteer-renderer?url=http://www.google.com
typepdf or screenshotRendering another type.http://puppeteer-renderer?url=http://www.google.com&type=pdf&margin.top=10px
animationTimeoutTimeout in millisecondsWaits for animations to finish before taking the screenshot. Only applicable to type screenshothttp://puppeteer-renderer?url=http://www.google.com&type=screenshot&animationTimeout=3000
(Extra options)Extra options (see puppeteer API doc)http://puppeteer-renderer?url=http://www.google.com&type=pdf&scale=2

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:

URLFilename
https://www.example.com/www.example.com.pdf
https://www.example.com:80/www.example.com.pdf
https://www.example.com/resourceresource.pdf
https://www.example.com/resource.extensionresource.pdf
https://www.example.com/path/path.pdf
https://www.example.com/path/to/pathto.pdf
https://www.example.com/path/to/resourceresource.pdf
https://www.example.com/path/to/resource.extresource.pdf

License

MIT

Copyright (c) 2017-present, Yeongjin Lee

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial