Skip to content
Start here

Get HTML content and screenshot.

POST/accounts/{account_id}/browser-rendering/snapshot

Returns the page’s HTML content and screenshot. Control page loading with gotoOptions and waitFor* options. Customize screenshots with viewport, fullPage, clip and others.

Security
API Token

The preferred authorization scheme for interacting with the Cloudflare API. Create a token.

Example:Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY
API Email + API Key

The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.

Example:X-Auth-Email: user@example.com

The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.

Example:X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194
Accepted Permissions (at least one required)
Browser Rendering Write
Path ParametersExpand Collapse
account_id: string

Account ID.

Query ParametersExpand Collapse
cacheTTL: optional number

Cache TTL default is 5s. Set to 0 to disable.

maximum86400
Body ParametersJSONExpand Collapse
body: { html, actionTimeout, addScriptTag, 17 more } or { url, actionTimeout, addScriptTag, 17 more }
One of the following:
{ html, actionTimeout, addScriptTag, 17 more }
html: string

Set the content of the page, eg: <h1>Hello World!!</h1>. Either html or url must be set.

minLength1
actionTimeout: optional number

The maximum duration allowed for the browser action to complete after the page has loaded (such as taking screenshots, extracting content, or generating PDFs). If this time limit is exceeded, the action stops and returns a timeout error.

maximum120000
addScriptTag: optional array of { id, content, type, url }

Adds a <script> tag into the page with the desired URL or content.

id: optional string
content: optional string
type: optional string
url: optional string
addStyleTag: optional array of { content, url }

Adds a <link rel="stylesheet"> tag into the page with the desired URL or a <style type="text/css"> tag with the content.

content: optional string
url: optional string
allowRequestPattern: optional array of string

Only allow requests that match the provided regex patterns, eg. ’/^.*.(css)’.

allowResourceTypes: optional array of "document" or "stylesheet" or "image" or 15 more

Only allow requests that match the provided resource types, eg. ‘image’ or ‘script’.

One of the following:
"document"
"stylesheet"
"image"
"media"
"font"
"script"
"texttrack"
"xhr"
"fetch"
"prefetch"
"eventsource"
"websocket"
"manifest"
"signedexchange"
"ping"
"cspviolationreport"
"preflight"
"other"
authenticate: optional { password, username }

Provide credentials for HTTP authentication.

password: string
minLength1
username: string
minLength1
bestAttempt: optional boolean

Attempt to proceed when ‘awaited’ events fail or timeout.

cookies: optional array of { name, value, domain, 11 more }

Check options.

name: string

Cookie name.

value: string
domain: optional string
expires: optional number
httpOnly: optional boolean
partitionKey: optional string
path: optional string
priority: optional "Low" or "Medium" or "High"
One of the following:
"Low"
"Medium"
"High"
sameParty: optional boolean
sameSite: optional "Strict" or "Lax" or "None"
One of the following:
"Strict"
"Lax"
"None"
secure: optional boolean
sourcePort: optional number
sourceScheme: optional "Unset" or "NonSecure" or "Secure"
One of the following:
"Unset"
"NonSecure"
"Secure"
url: optional string
emulateMediaType: optional string
gotoOptions: optional { referer, referrerPolicy, timeout, waitUntil }

Check options.

referer: optional string
referrerPolicy: optional string
timeout: optional number
maximum60000
waitUntil: optional "load" or "domcontentloaded" or "networkidle0" or "networkidle2" or array of "load" or "domcontentloaded" or "networkidle0" or "networkidle2"
One of the following:
"load" or "domcontentloaded" or "networkidle0" or "networkidle2"
One of the following:
"load"
"domcontentloaded"
"networkidle0"
"networkidle2"
array of "load" or "domcontentloaded" or "networkidle0" or "networkidle2"
One of the following:
"load"
"domcontentloaded"
"networkidle0"
"networkidle2"
rejectRequestPattern: optional array of string

Block undesired requests that match the provided regex patterns, eg. ’/^.*.(css)’.

rejectResourceTypes: optional array of "document" or "stylesheet" or "image" or 15 more

Block undesired requests that match the provided resource types, eg. ‘image’ or ‘script’.

One of the following:
"document"
"stylesheet"
"image"
"media"
"font"
"script"
"texttrack"
"xhr"
"fetch"
"prefetch"
"eventsource"
"websocket"
"manifest"
"signedexchange"
"ping"
"cspviolationreport"
"preflight"
"other"
screenshotOptions: optional { captureBeyondViewport, clip, fromSurface, 5 more }
captureBeyondViewport: optional boolean
clip: optional { height, width, x, 2 more }
height: number
width: number
x: number
y: number
scale: optional number
fromSurface: optional boolean
fullPage: optional boolean
omitBackground: optional boolean
optimizeForSpeed: optional boolean
quality: optional number
type: optional "png" or "jpeg" or "webp"
One of the following:
"png"
"jpeg"
"webp"
setExtraHTTPHeaders: optional map[string]
setJavaScriptEnabled: optional boolean
userAgent: optional string
viewport: optional { height, width, deviceScaleFactor, 3 more }

Check options.

height: number
width: number
deviceScaleFactor: optional number
hasTouch: optional boolean
isLandscape: optional boolean
isMobile: optional boolean
waitForSelector: optional { selector, hidden, timeout, visible }

Wait for the selector to appear in page. Check options.

selector: string
hidden: optional true
timeout: optional number
maximum120000
visible: optional true
waitForTimeout: optional number

Waits for a specified timeout before continuing.

maximum120000
{ url, actionTimeout, addScriptTag, 17 more }
url: string

URL to navigate to, eg. https://example.com.

formaturi
actionTimeout: optional number

The maximum duration allowed for the browser action to complete after the page has loaded (such as taking screenshots, extracting content, or generating PDFs). If this time limit is exceeded, the action stops and returns a timeout error.

maximum120000
addScriptTag: optional array of { id, content, type, url }

Adds a <script> tag into the page with the desired URL or content.

id: optional string
content: optional string
type: optional string
url: optional string
addStyleTag: optional array of { content, url }

Adds a <link rel="stylesheet"> tag into the page with the desired URL or a <style type="text/css"> tag with the content.

content: optional string
url: optional string
allowRequestPattern: optional array of string

Only allow requests that match the provided regex patterns, eg. ’/^.*.(css)’.

allowResourceTypes: optional array of "document" or "stylesheet" or "image" or 15 more

Only allow requests that match the provided resource types, eg. ‘image’ or ‘script’.

One of the following:
"document"
"stylesheet"
"image"
"media"
"font"
"script"
"texttrack"
"xhr"
"fetch"
"prefetch"
"eventsource"
"websocket"
"manifest"
"signedexchange"
"ping"
"cspviolationreport"
"preflight"
"other"
authenticate: optional { password, username }

Provide credentials for HTTP authentication.

password: string
minLength1
username: string
minLength1
bestAttempt: optional boolean

Attempt to proceed when ‘awaited’ events fail or timeout.

cookies: optional array of { name, value, domain, 11 more }

Check options.

name: string

Cookie name.

value: string
domain: optional string
expires: optional number
httpOnly: optional boolean
partitionKey: optional string
path: optional string
priority: optional "Low" or "Medium" or "High"
One of the following:
"Low"
"Medium"
"High"
sameParty: optional boolean
sameSite: optional "Strict" or "Lax" or "None"
One of the following:
"Strict"
"Lax"
"None"
secure: optional boolean
sourcePort: optional number
sourceScheme: optional "Unset" or "NonSecure" or "Secure"
One of the following:
"Unset"
"NonSecure"
"Secure"
url: optional string
emulateMediaType: optional string
gotoOptions: optional { referer, referrerPolicy, timeout, waitUntil }

Check options.

referer: optional string
referrerPolicy: optional string
timeout: optional number
maximum60000
waitUntil: optional "load" or "domcontentloaded" or "networkidle0" or "networkidle2" or array of "load" or "domcontentloaded" or "networkidle0" or "networkidle2"
One of the following:
"load" or "domcontentloaded" or "networkidle0" or "networkidle2"
One of the following:
"load"
"domcontentloaded"
"networkidle0"
"networkidle2"
array of "load" or "domcontentloaded" or "networkidle0" or "networkidle2"
One of the following:
"load"
"domcontentloaded"
"networkidle0"
"networkidle2"
rejectRequestPattern: optional array of string

Block undesired requests that match the provided regex patterns, eg. ’/^.*.(css)’.

rejectResourceTypes: optional array of "document" or "stylesheet" or "image" or 15 more

Block undesired requests that match the provided resource types, eg. ‘image’ or ‘script’.

One of the following:
"document"
"stylesheet"
"image"
"media"
"font"
"script"
"texttrack"
"xhr"
"fetch"
"prefetch"
"eventsource"
"websocket"
"manifest"
"signedexchange"
"ping"
"cspviolationreport"
"preflight"
"other"
screenshotOptions: optional { captureBeyondViewport, clip, fromSurface, 5 more }
captureBeyondViewport: optional boolean
clip: optional { height, width, x, 2 more }
height: number
width: number
x: number
y: number
scale: optional number
fromSurface: optional boolean
fullPage: optional boolean
omitBackground: optional boolean
optimizeForSpeed: optional boolean
quality: optional number
type: optional "png" or "jpeg" or "webp"
One of the following:
"png"
"jpeg"
"webp"
setExtraHTTPHeaders: optional map[string]
setJavaScriptEnabled: optional boolean
userAgent: optional string
viewport: optional { height, width, deviceScaleFactor, 3 more }

Check options.

height: number
width: number
deviceScaleFactor: optional number
hasTouch: optional boolean
isLandscape: optional boolean
isMobile: optional boolean
waitForSelector: optional { selector, hidden, timeout, visible }

Wait for the selector to appear in page. Check options.

selector: string
hidden: optional true
timeout: optional number
maximum120000
visible: optional true
waitForTimeout: optional number

Waits for a specified timeout before continuing.

maximum120000
ReturnsExpand Collapse
meta: { status, title }
status: optional number
title: optional string
success: boolean

Response status.

errors: optional array of { code, message }
code: number

Error code.

message: string

Error message.

result: optional { content, screenshot }
content: string

HTML content.

screenshot: string

Base64 encoded image.

Get HTML content and screenshot.

curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/browser-rendering/snapshot \
    -H 'Content-Type: application/json' \
    -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
    -d '{
          "html": "<h1>Hello World!</h1>"
        }'
{
  "meta": {
    "status": 0,
    "title": "title"
  },
  "success": true,
  "errors": [
    {
      "code": 0,
      "message": "message"
    }
  ],
  "result": {
    "content": "content",
    "screenshot": "screenshot"
  }
}
{
  "errors": [
    {
      "code": 2001,
      "message": "Rate limit exceeded"
    }
  ],
  "success": false
}
Returns Examples
{
  "meta": {
    "status": 0,
    "title": "title"
  },
  "success": true,
  "errors": [
    {
      "code": 0,
      "message": "message"
    }
  ],
  "result": {
    "content": "content",
    "screenshot": "screenshot"
  }
}
{
  "errors": [
    {
      "code": 2001,
      "message": "Rate limit exceeded"
    }
  ],
  "success": false
}