Skip to content
Start here

Dynamic Script - execute code and return browser session details.

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

Acquires a browser session and runs the provided code in it. The session stays open for reuse; close it with DELETE /devtools/browser/:sessionId or browser.close(), otherwise it ends at the idle timeout.

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
browser: optional "kitesurf"

Rendering backend for this script. Set to kitesurf to run it on Kitesurf (beta), which supports CDP only and rejects keep_alive, lab and recording.

keep_alive: optional number

Keep-alive time in milliseconds

maximum1200000
minimum10000
lab: optional boolean

Use experimental browser.

recording: optional boolean

Record the browser session. Retrieve it with GET /recording/:session_id.

Body ParametersJSONExpand Collapse
code: string

Function body executed against the selected library’s runner.

library: optional "playwright" or "puppeteer"

Library the script runs with. Defaults to raw CDP when omitted.

One of the following:
"playwright"
"puppeteer"
timeout: optional number

Maximum script run time in milliseconds.

maximum120000
minimum1
ReturnsExpand Collapse
result: string or number or boolean or 2 more

The script’s return value, or null when it returned nothing. Arrays nested inside arrays are also returned, but this schema does not describe them.

One of the following:
string
number
boolean
map[unknown]
array of string or number or boolean or map[unknown]
One of the following:
string
number
boolean
map[unknown]
success: true

Dynamic Script - execute code and return browser session details.

curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/browser-rendering/script \
    -H 'Content-Type: application/json' \
    -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
    -d '{
          "code": "code"
        }'
{
  "result": "string",
  "success": true
}
{
  "errors": [
    {
      "code": 2001,
      "message": "Rate limit exceeded"
    }
  ],
  "success": false
}
Returns Examples
{
  "result": "string",
  "success": true
}
{
  "errors": [
    {
      "code": 2001,
      "message": "Rate limit exceeded"
    }
  ],
  "success": false
}