Skip to content
Start here

Dynamic Script - execute code in an existing browser session.

client.BrowserRendering.Script.Execute(ctx, sessionID, params) (*ScriptExecuteResponseUnion, error)
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
sessionID string

Browser session ID

formatuuid
params ScriptExecuteParams
AccountID param.Field[string]

Path param: Account ID.

Code param.Field[string]

Body param: Function body executed against the selected library’s runner.

Library param.Field[ScriptExecuteParamsLibrary]Optional

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

const ScriptExecuteParamsLibraryPlaywright ScriptExecuteParamsLibrary = "playwright"
const ScriptExecuteParamsLibraryPuppeteer ScriptExecuteParamsLibrary = "puppeteer"
TargetID param.Field[string]Optional

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

Timeout param.Field[int64]Optional

Body param: Maximum script run time in milliseconds.

maximum120000
minimum1
ReturnsExpand Collapse
type ScriptExecuteResponseUnion interface{…}

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:
UnionString
UnionFloat
UnionBool
type ScriptExecuteResponseMap map[string, unknown]
type ScriptExecuteResponseArray []ScriptExecuteResponseArrayUnionItem
One of the following:
UnionString
UnionFloat
UnionBool
type ScriptExecuteResponseArrayMap map[string, unknown]

Dynamic Script - execute code in an existing browser session.

package main

import (
  "context"
  "fmt"

  "github.com/cloudflare/cloudflare-go"
  "github.com/cloudflare/cloudflare-go/browser_rendering"
  "github.com/cloudflare/cloudflare-go/option"
)

func main() {
  client := cloudflare.NewClient(
    option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"),
  )
  response, err := client.BrowserRendering.Script.Execute(
    context.TODO(),
    "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
    browser_rendering.ScriptExecuteParams{
      AccountID: cloudflare.F("account_id"),
      Code: cloudflare.F("code"),
    },
  )
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", response)
}
{
  "result": "string",
  "success": true
}
Returns Examples
{
  "result": "string",
  "success": true
}