Screenshot API

This document describes the screenshot functionality/endpoint, its associated HTTP header options, and possible error responses.


Screenshot Path: /screenshot/$URL

Example URL:

The target $URL is obviously part of the path, but do not re-encode or re-escape it beyond what you'd enter into a browser URL field. Both UTF-8 encoding and percent-encoding are acceptable.

Related links: 


Send your secret API token (you'll get it after creating an account) as a header with all your requests to avoid rate limiting.
  • curl --header "X-Prerender-Token: secret-token"

Take screenshot of a webpage (URL)

A webpage screenshot API. Try it in your browser:


curl > out.png

Node.js client

// npm install prerendercloud
await prerendercloud.screenshot("", {
  deviceWidth: 800,
  deviceHeight: 600,
  viewportWidth: 640,
  viewportHeight: 480,
  viewportX: 0,
  viewportY: 0,
  format: "webp", // Default: png, other options: webp, jpeg
  // viewportQuerySelector: "#open-graph-div",
  // viewportQuerySelectorPadding: 10,
  // emulatedMedia: "screen",
  // viewportScale: 2, // Default: 1, min: 0.1, max: 3.0
  // isMobile: false, // Default: false, whether the meta viewport tag is taken into account

Optional HTTP Headers for Device Metrics

  • Overrides device screen width (default: 1366)
  • curl --header "prerender-device-width: 800"
  • Overrides device screen height (default: 768)
  • curl --header "prerender-device-height: 600"
  • Whether to emulate mobile device (default: false).

    This includes viewport meta tag, overlay scrollbars, text autosizing and more. In other words, whether the meta viewport tag is taken into account.

    an example of "viewport meta tag":
  • curl --header "prerender-device-is-mobile: true"

Optional HTTP Headers for Screenshots

  • Specify a DOM element on the page to take a screenshot of, as opposed to the default of the entire window
  • curl --header "Prerender-Viewport-Query-Selector: #open-graph-div"
  • Use with query-selector option to add padding around the DOM element
  • curl --header "prerender-viewport-query-selector-padding: 10"
  • Width of viewport (screenshots only, not compatible with query selector)
  • curl --header "prerender-viewport-width: 100"
  • Height of viewport (screenshots only, not compatible with query selector)
  • curl --header "prerender-viewport-height: 100"
  • Viewport X offset in pixels (screenshots only, not compatible with query selector)
  • curl --header "prerender-viewport-x: 0"
  • Viewport Y offset in pixels (screenshots only, not compatible with query selector)
  • curl --header "prerender-viewport-y: 0"
  • Page scale factor. Default: 1, min: 0.1, max: 3.0
  • curl --header "prerender-viewport-scale: 1.5"
  • Default is png, choose from: jpeg, png, webp
  • curl --header "prerender-screenshot-format: webp"

Optional HTTP Headers for Browser Emulated Media

  • Emulates the given media type or media feature for CSS media queries

    default: screen

    Possible values are: screen, print, braille, embossed, handheld, projection, speech, tty, tv
  • curl --header "Prerender-Emulated-Media: screen"

Optional HTTP Headers for Headless-Render-API Server Behavior

  • Waits longer than normal for a page to finish rendering. Similar to Puppeteer's { waitUntil: 'networkidle' }. Useful for pages that depend on AJAX/XHR that fire late or IPFS hosted pages
  • curl --header "Prerender-Wait-Extra-Long: true"
  • By default, will wait for all ws activity to finish, but it doesn't make sense to "wait" for them to finish if they never stop. An example: real time prices on a stock price website.
  • curl --header "prerender-dont-wait-for-web-sockets: true"
  • By default, sends cookies back to the server. Use this to block them.
  • curl --header "prerender-block-cookies: true"

HTTP Error Codes

  • Invalid Request
  • There will be an error message in the HTML, fix your request and retry
  • Example causes:
    • malformed URL
    • a localhost URL/IP
    • or a page responds with content-type: application/octet-stream
  • Rate limited
  • Requests made without API tokens (or expired/missing billing information) will get this - see pricing
  • General Error
  • Example causes:
    • 10s (timeout) while waiting for a page to finish rendering (waits until all in-flight requests finish, load event, domContent event etc.)
    • or HTTPS Page is making HTTP (non secure) requests
    • ...or a random bug on our end
  • The error will show up in the web UI (after you sign in)
  • Bad Gateway (your origin returned 5xx)
  • It means we received a 5xx when trying to visit your page
  • Or it means we received a 403 (forbidden). Typically this means your page is behind a login wall or a firewall (like Cloudflare) is blocking the headless-render-api user-agent (make an exception to allow user-agents matching /prerendercloud/)
  • Probably not retryable. It depends on the site you're requesting. If it's your site, make sure it's up and running correctly
  • Over capacity (Rare)
  • Retry the request with some backoff
  • We'll see the error and our autoscaler will increase capacity within 5 minutes, but you should email us anyway:
  • Gateway Timeout (Rare)
  • Retry the request with some backoff
  • This is unexpected and should not happen. We'll see it, but you should email us anyway: