Skip to content
Start here

Dynamic Script - execute code and return browser session details.

client.BrowserRendering.Script.New(ctx, params) (*ScriptNewResponseUnion, error)
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
params ScriptNewParams
AccountID param.Field[string]

Path param: Account ID.

Code param.Field[string]

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

Browser param.Field[ScriptNewParamsBrowser]Optional

Query param: 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.

const ScriptNewParamsBrowserKitesurf ScriptNewParamsBrowser = "kitesurf"
KeepAlive param.Field[float64]Optional

Query param: Keep-alive time in milliseconds

maximum1200000
minimum10000
Lab param.Field[bool]Optional

Query param: Use experimental browser.

Recording param.Field[bool]Optional

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

Library param.Field[ScriptNewParamsLibrary]Optional

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

const ScriptNewParamsLibraryPlaywright ScriptNewParamsLibrary = "playwright"
const ScriptNewParamsLibraryPuppeteer ScriptNewParamsLibrary = "puppeteer"
Timeout param.Field[int64]Optional

Body param: Maximum script run time in milliseconds.

maximum120000
minimum1
ReturnsExpand Collapse
type ScriptNewResponseUnion 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 ScriptNewResponseMap map[string, unknown]
type ScriptNewResponseArray []ScriptNewResponseArrayUnionItem
One of the following:
UnionString
UnionFloat
UnionBool
type ScriptNewResponseArrayMap map[string, unknown]

Dynamic Script - execute code and return browser session details.

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"),
  )
  script, err := client.BrowserRendering.Script.New(context.TODO(), browser_rendering.ScriptNewParams{
    AccountID: cloudflare.F("account_id"),
    Code: cloudflare.F("code"),
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", 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
}