Awesome Open Source
Awesome Open Source


Render JavaScript-rendered page as HTML/PDF/mhtml/png/jpeg using headless Chrome

Install Chrome

Headless mode is supported in Chrome stable 59+ and unstable/dev channel, you should be able to install it via:

Start Chrome Headless

$ google-chrome --headless --remote-debugging-port=9222 --disable-gpu "about:blank"

To disable image loading, add --blink-settings=imagesEnabled=false argument:

$ google-chrome --headless --remote-debugging-port=9222 --disable-gpu --blink-settings=imagesEnabled=false "about:blank"

Install Prerender

$ pip install -U prerender

Start Prerender

As standalone application:

$ prerender

To run it under gunicorn:

$ gunicorn --bind --worker-class sanic.worker.GunicornWorker

How does it work

Say you deployed Prerender under, to render you can do:

$ # render HTML
$ curl
$ curl
$ # render mhtml
$ curl
$ # render PDF
$ curl
$ # render png
$ curl
$ # render jpeg
$ curl


Settings are mostly configured by environment variables.

ENV default value description
HOST Prerender listen host
PORT 8000 Prerender listen port
DEBUG false Toggle debug mode
PRERENDER_TIMEOUT 30 renderring timeout
PAGE_DONE_CHECK_TIMEOUT 200 Number of milliseconds between the interval of checking whether the page is done loading or not
CONCURRENCY 2 * CPU count Chrome pages count
MAX_ITERATIONS 200 Restart Chrome page after rendering this many pages
CHROME_HOST localhost Chrome remote debugging host
CHROME_PORT 9222 Chrome remote debugging port
USER_AGENT Chrome User Agent
BLOCK_FONTS 1 Block web fonts loading, set to 0 to allow fonts loading
ALLOWED_DOMAINS Domains allowed for renderring, comma seperated
CACHE_BACKEND dummy Cache backend, dummy, disk, s3
CACHE_LIVE_TIME 3600 Disk cache live seconds
CACHE_ROOT_DIR /tmp/prerender Disk cache root directory
S3_SERVER S3 server address
S3_ACCESS_KEY S3 access key
S3_SECRET_KEY S3 secret key
S3_REGION S3 region
S3_BUCKET prerender S3 bucket name
SENTRY_DSN Sentry DSN, for exception monitoring
ENABLE_CIRCUIT_BREAKER false enable circuit breaker
CIRCUIT_BREAKER_FAIL_MAX 5 maximum failures per browser/bot before circuit breaker open
CIRCUIT_BREAKER_RESET_TIMEOUT 60 circuit breaker reset timeout in seconds

Configure client

Please view the original NodeJs version prerender README.



Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
python (50,867
prerender (22
server-rendering (21

Find Open Source By Browsing 7,000 Topics Across 59 Categories