browserless docs

browserless docs

  • Quick Start
  • Docker
  • Libraries
  • FAQ
  • Blog
  • Sign-up

›APIs

Hosted Service

  • Quick Start
  • How it works
  • GraphQL API
  • Best Practices
  • Terminology
  • Using your token

Docker

  • Quick Start
  • Configuration
  • Webhooks
  • Extending

APIs

  • /content
  • /download
  • /function
  • /pdf
  • /screencast
  • /screenshot
  • /scrape
  • /stats
  • /workspace

Libraries

  • Puppeteer
  • Playwright
  • Selenium
  • Capybara
  • .NET
  • Java
  • Python
  • Go (chromedp)

Recipes

  • Dealing with downloads
  • Using a Proxy
  • Watching sessions

Options

  • Launch Options
  • Using API /GET

/pdf API

The pdf API allows for simple navigation to a site and capturing a pdf. browserless will respond with a Content-Type of application/pdf, and a Buffer of the pdf file. Similar to screenshots, this also exposes puppeteer's pdf options via an options property in the JSON body for granular control.

If you want to see all the options check out the schema for it here on GitHub.

This route requires either a url or html property in the JSON body. When html is present browserless will render the HTML for you and capture the PDF

Take a PDF of example.com

// JSON body
// `options` are the options available via puppeteer's .screenshot method
{
  "url": "https://example.com/",
  "options": {
    "displayHeaderFooter": true,
    "printBackground": false,
    "format": "A0"
  }
}

cURL (with an API token)

curl -X POST \
  https://chrome.browserless.io/pdf?token=MY_API_TOKEN \
  -H 'Cache-Control: no-cache' \
  -H 'Content-Type: application/json' \
  -d '{
  "url": "https://example.com/",
  "options": {
    "displayHeaderFooter": true,
    "printBackground": false,
    "format": "A0"
  }
}'

Custom options

The /pdf route has a few special custom options that make it more usable and configurable. We've added these options based on feedback from you in hope that it will help gather best-practices in a single place.

gotoOptions

The gotoOptions is an object that's passed directly into puppeteer's page.goto call so that you can specify things like alternative loaded events. See puppeteer's goto options for more information.

Example (with an API token)

curl -X POST \
  https://chrome.browserless.io/pdf?token=MY_API_TOKEN \
  -H 'Cache-Control: no-cache' \
  -H 'Content-Type: application/json' \
  -d '{
  "url": "https://example.com/",
  "gotoOptions": {
    "waitUntil": "networkidle2",
  },
  "options": {
    "displayHeaderFooter": true,
    "printBackground": false,
    "format": "A0"
  }
}'

safeMode

Because longer pages can crash trigger a "Page Crashed!" error when doing a page.pdf invocation, we've implemented a "safe" way to generate PDF's of bigger websites. When set to true, safeMode will:

  • Capture PDF's one page at a time in-memory.
  • Once all pages are in memory we connect them together.
  • Compress the PDF so it's more efficiently transported over the network.
  • Return the resulting PDF as a binary via application/pdf.

Please note that when using safeMode that it will likely take a while longer to process the request, and the resulting PDF file may be larger.

Example (with an API token)

curl -X POST \
  https://chrome.browserless.io/pdf?token=MY_API_TOKEN \
  -H 'Cache-Control: no-cache' \
  -H 'Content-Type: application/json' \
  -d '{
  "url": "https://example.com/",
  "safeMode": true,
  "options": {
    "displayHeaderFooter": true,
    "printBackground": false,
    "format": "A0"
  }
}'
← /function/screencast →
browserless docs
Docs
Quick StartDocker DocsChrome API
Community
SlackTwitter
More
GitHubStar