Render JavaScript-rendered page as HTML using headless Chrome
Project description
# prerender
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:
https://www.google.com/chrome/browser/beta.html?platform=linux
## Start Chrome Headless
```bash
$ google-chrome --headless --remote-debugging-port=9222 --disable-gpu "about:blank"
```
## Install Prerender
```bash
$ pip install -U prerender
```
## Start Prerender
As standalone application:
```bash
$ prerender
```
To run it under gunicorn:
```bash
$ gunicorn --bind 0.0.0.0:3000 --worker-class sanic.worker.GunicornWorker prerender.app:app
```
## How does it work
Say you deployed Prerender under `http://prerender.example.com:8000`, to render `http://example.com` you can do:
```bash
$ # render HTML
$ curl http://prerender.example.com:8000/http://example.com
$ curl http://prerender.example.com:8000/html/http://example.com
$ # render mhtml
$ curl http://prerender.example.com:8000/mhtml/http://example.com
$ # render PDF
$ curl http://prerender.example.com:8000/pdf/http://example.com
$ # render png
$ curl http://prerender.example.com:8000/png/http://example.com
$ # render jpeg
$ curl http://prerender.example.com:8000/jpeg/http://example.com
```
## Configuration
Settings are mostly configured by environment variables.
| ENV | default value | description |
|----------------------------|------------------|-----------------------------------------------------|
| HOST | 0.0.0.0 | Prerender listen host |
| PORT | 8000 | Prerender listen port |
| DEBUG | false | Toggle debug mode |
| PRERENDER_TIMEOUT | 30 | renderring timeout |
| 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 |
| 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.amazonaws.com | 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 |
## Configure client
Please view the original NodeJs version [prerender](https://github.com/prerender/prerender#official-middleware) README.
## License
MIT
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:
https://www.google.com/chrome/browser/beta.html?platform=linux
## Start Chrome Headless
```bash
$ google-chrome --headless --remote-debugging-port=9222 --disable-gpu "about:blank"
```
## Install Prerender
```bash
$ pip install -U prerender
```
## Start Prerender
As standalone application:
```bash
$ prerender
```
To run it under gunicorn:
```bash
$ gunicorn --bind 0.0.0.0:3000 --worker-class sanic.worker.GunicornWorker prerender.app:app
```
## How does it work
Say you deployed Prerender under `http://prerender.example.com:8000`, to render `http://example.com` you can do:
```bash
$ # render HTML
$ curl http://prerender.example.com:8000/http://example.com
$ curl http://prerender.example.com:8000/html/http://example.com
$ # render mhtml
$ curl http://prerender.example.com:8000/mhtml/http://example.com
$ # render PDF
$ curl http://prerender.example.com:8000/pdf/http://example.com
$ # render png
$ curl http://prerender.example.com:8000/png/http://example.com
$ # render jpeg
$ curl http://prerender.example.com:8000/jpeg/http://example.com
```
## Configuration
Settings are mostly configured by environment variables.
| ENV | default value | description |
|----------------------------|------------------|-----------------------------------------------------|
| HOST | 0.0.0.0 | Prerender listen host |
| PORT | 8000 | Prerender listen port |
| DEBUG | false | Toggle debug mode |
| PRERENDER_TIMEOUT | 30 | renderring timeout |
| 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 |
| 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.amazonaws.com | 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 |
## Configure client
Please view the original NodeJs version [prerender](https://github.com/prerender/prerender#official-middleware) README.
## License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
prerender-0.8.1.tar.gz
(14.5 kB
view details)
Built Distribution
prerender-0.8.1-py3-none-any.whl
(18.8 kB
view details)
File details
Details for the file prerender-0.8.1.tar.gz
.
File metadata
- Download URL: prerender-0.8.1.tar.gz
- Upload date:
- Size: 14.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9cbeccad9058774d8546cfcba3034185b5f35aa68be5e6976cb955e14a73252 |
|
MD5 | 26335414b046d8b889fbdc2b8faddc29 |
|
BLAKE2b-256 | 79e9b5d286a92682e1e6936d75687c6bdf3044a6289f23726ee6fafdd8539a1b |
File details
Details for the file prerender-0.8.1-py3-none-any.whl
.
File metadata
- Download URL: prerender-0.8.1-py3-none-any.whl
- Upload date:
- Size: 18.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 758aab730d33262ef0c068fdab1c5969a46a6a3305a6877f5d6bffa3e9927fb5 |
|
MD5 | 8ef0802a04834752d266b635829c235b |
|
BLAKE2b-256 | 298be43f8eeb292463a6c3b9696a718433aa028e749d9cfc01812d7b300a30f5 |