Skip to content
Start here

Dynamic Script - execute code and return browser session details.

browser_rendering.script.create(ScriptCreateParams**kwargs) -> ScriptCreateResponse
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
ParametersExpand Collapse
account_id: str

Account ID.

code: str

Function body executed against the selected library’s runner.

browser: Optional[Literal["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[float]

Keep-alive time in milliseconds

maximum1200000
minimum10000
lab: Optional[bool]

Use experimental browser.

recording: Optional[bool]

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

library: Optional[Literal["playwright", "puppeteer"]]

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

One of the following:
"playwright"
"puppeteer"
api_timeout: Optional[int]

Maximum script run time in milliseconds.

maximum120000
minimum1
ReturnsExpand Collapse
Union[Optional[str], Optional[float], Optional[bool], 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:
Optional[str]
Optional[float]
Optional[bool]
Optional[Dict[str, object]]
Optional[List[Union[Optional[str], Optional[float], Optional[bool], Optional[Dict[str, object]]]]]
One of the following:
Optional[str]
Optional[float]
Optional[bool]
Optional[Dict[str, object]]

Dynamic Script - execute code and return browser session details.

import os
from cloudflare import Cloudflare

client = Cloudflare(
    api_token=os.environ.get("CLOUDFLARE_API_TOKEN"),  # This is the default and can be omitted
)
script = client.browser_rendering.script.create(
    account_id="account_id",
    code="code",
)
print(script)
{
  "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
}