Skip to content
Start here

Scrape elements.

client.browserRendering.scrape.create(ScrapeCreateParams { account_id, elements, cacheTTL, 20 more } params, RequestOptionsoptions?): ScrapeCreateResponse { results, selector }
POST/accounts/{account_id}/browser-rendering/scrape

Get meta attributes like height, width, text and others of selected elements.

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
ParametersExpand Collapse
params: ScrapeCreateParams { account_id, elements, cacheTTL, 20 more }
account_id: string

Path param: Account ID.

elements: Array<Element>

Body param

selector: string
cacheTTL?: number

Query param: Cache TTL default is 5s. Set to 0 to disable.

maximum86400
minimum0
actionTimeout?: number

Body param: 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?: Array<AddScriptTag>

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

id?: string
content?: string
type?: string
url?: string
formaturi
addStyleTag?: Array<AddStyleTag>

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

content?: string
url?: string
formaturi
allowRequestPattern?: Array<string>

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

allowResourceTypes?: Array<"document" | "stylesheet" | "image" | 15 more>

Body param: 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?: Authenticate

Body param: Provide credentials for HTTP authentication.

password: string
minLength1
username: string
minLength1
bestAttempt?: boolean

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

cookies?: Array<Cookie>

Body param: Check options.

name: string

Cookie name.

value: string
domain?: string
expires?: number
httpOnly?: boolean
partitionKey?: string
path?: string
priority?: "Low" | "Medium" | "High"
One of the following:
"Low"
"Medium"
"High"
sameParty?: boolean
sameSite?: "Strict" | "Lax" | "None"
One of the following:
"Strict"
"Lax"
"None"
secure?: boolean
sourcePort?: number
sourceScheme?: "Unset" | "NonSecure" | "Secure"
One of the following:
"Unset"
"NonSecure"
"Secure"
url?: string
emulateMediaType?: string

Body param

gotoOptions?: GotoOptions

Body param: Check options.

referer?: string
referrerPolicy?: string
timeout?: number
maximum60000
waitUntil?: "load" | "domcontentloaded" | "networkidle0" | "networkidle2" | Array<"load" | "domcontentloaded" | "networkidle0" | "networkidle2">
One of the following:
"load" | "domcontentloaded" | "networkidle0" | "networkidle2"
"load"
"domcontentloaded"
"networkidle0"
"networkidle2"
Array<"load" | "domcontentloaded" | "networkidle0" | "networkidle2">
"load"
"domcontentloaded"
"networkidle0"
"networkidle2"
html?: string

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

minLength1
rejectRequestPattern?: Array<string>

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

rejectResourceTypes?: Array<"document" | "stylesheet" | "image" | 15 more>

Body param: 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"
setExtraHTTPHeaders?: Record<string, string>

Body param

setJavaScriptEnabled?: boolean

Body param

url?: string

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

formaturi
userAgent?: string

Body param

viewport?: Viewport

Body param: Check options.

height: number
width: number
deviceScaleFactor?: number
hasTouch?: boolean
isLandscape?: boolean
isMobile?: boolean
waitForSelector?: WaitForSelector

Body param: Wait for the selector to appear in page. Check options.

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

Body param: Waits for a specified timeout before continuing.

maximum120000
ReturnsExpand Collapse
ScrapeCreateResponse = Array<ScrapeCreateResponseItem>
results: Results { attributes, height, html, 4 more }
attributes: Array<Attribute>
name: string

Attribute name.

value: string

Attribute value.

height: number

Element height.

html: string

HTML content.

left: number

Element left.

text: string

Text content.

top: number

Element top.

width: number

Element width.

selector: string

Selector.

Scrape elements.

import Cloudflare from 'cloudflare';

const client = new Cloudflare({
  apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted
});

const scrapes = await client.browserRendering.scrape.create({
  account_id: 'account_id',
  elements: [{ selector: 'h1' }],
  url: 'https://www.example.com/',
});

console.log(scrapes);
{
  "result": [
    {
      "results": {
        "attributes": [
          {
            "name": "name",
            "value": "value"
          }
        ],
        "height": 0,
        "html": "html",
        "left": 0,
        "text": "text",
        "top": 0,
        "width": 0
      },
      "selector": "selector"
    }
  ],
  "success": true,
  "errors": [
    {
      "code": 0,
      "message": "message"
    }
  ]
}
{
  "errors": [
    {
      "code": 2001,
      "message": "Rate limit exceeded"
    }
  ],
  "success": false
}
Returns Examples
{
  "result": [
    {
      "results": {
        "attributes": [
          {
            "name": "name",
            "value": "value"
          }
        ],
        "height": 0,
        "html": "html",
        "left": 0,
        "text": "text",
        "top": 0,
        "width": 0
      },
      "selector": "selector"
    }
  ],
  "success": true,
  "errors": [
    {
      "code": 0,
      "message": "message"
    }
  ]
}
{
  "errors": [
    {
      "code": 2001,
      "message": "Rate limit exceeded"
    }
  ],
  "success": false
}