Skip to content
Start here

Dynamic Script - execute code in an existing browser session.

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

Runs the provided code in an existing browser session. The session stays open; 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.

session_id: string

Browser session ID

formatuuid
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"
targetId: optional string

Page target the script attaches to. Defaults to the session’s first page.

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 in an existing browser session.

curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/browser-rendering/script/$SESSION_ID \
    -H 'Content-Type: application/json' \
    -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
    -d '{
          "code": "code"
        }'
{
  "result": "string",
  "success": true
}
Returns Examples
{
  "result": "string",
  "success": true
}