Skip to content
Start here

Dynamic Script - execute code in an existing browser session.

browser_rendering.script.execute(strsession_id, ScriptExecuteParams**kwargs) -> ScriptExecuteResponse
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
ParametersExpand Collapse
account_id: str

Account ID.

session_id: str

Browser session ID

formatuuid
code: str

Function body executed against the selected library’s runner.

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

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

One of the following:
"playwright"
"puppeteer"
target_id: Optional[str]

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

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

import os
from cloudflare import Cloudflare

client = Cloudflare(
    api_token=os.environ.get("CLOUDFLARE_API_TOKEN"),  # This is the default and can be omitted
)
response = client.browser_rendering.script.execute(
    session_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
    account_id="account_id",
    code="code",
)
print(response)
{
  "result": "string",
  "success": true
}
Returns Examples
{
  "result": "string",
  "success": true
}