---
type: "post"
id: "run-custom-scripts-in-browser-run-with-script-ed03b3"
slug: "run-custom-scripts-in-browser-run-with-script-ed03b3"
title: "Run custom scripts in Browser Run with /script"
description: "Send a JavaScript function using Playwright, Puppeteer, or the Chrome DevTools Protocol in a single API request; Browser Run executes it in an isolated Worker connected to a browser session."
retrieval_nugget: "Send a JavaScript function using Playwright, Puppeteer, or the Chrome DevTools Protocol in a single API request; Browser Run executes it in an isolated Worker connected to a browser session."
published_at: "2026-11-27"
updated_at: "2026-11-27"
record_date: "2026-11-27"
date_kind: "published_at"
topics: ["automation","developer-tools","sandbox"]
entities: ["Cloudflare","Browser Run","Kitesurf","Playwright","Puppeteer"]
related_patterns: ["agent-protocols-become-interoperability-layer"]
novelty_label: "new_fact"
what_changed: "Cloudflare adds a /script API to Browser Run, letting developers execute Playwright, Puppeteer, or CDP automation in an isolated Worker and optionally run CDP scripts on Kitesurf."
prior_refs: []
source_url: "https://developers.cloudflare.com/changelog/post/2026-11-20-script-endpoint"
source_urls: ["https://developers.cloudflare.com/changelog/post/2026-11-20-script-endpoint"]
production: {"schema":"newruntime-production-v1","desk":"newsroom","first_seen_at":"2026-11-27T19:21:52.129Z","independent_sources":1,"notes_synthesized":null,"writer_model":"gpt-6-luna","critic":null,"checks":["primary_source_verified","source_fresh","one_story","copy_contract"],"novelty":{"label":"new_fact","confidence":"medium"},"editorial_value":"high","human_review":"selective"}
citations: [{"claim":"","quotes":["View RSS feeds Subscribe to … the new /script endpoints .","Cloudflare added Browser Run endpoints that execute a JavaScript function in an isolated Worker connected to a browser session, without requiring users to deploy their own Worker."],"cite_url":"https://developers.cloudflare.com/changelog/post/2026-11-20-script-endpoint#:~:text=View%20RSS%20feeds%20Subscribe%20to,the%20new%20%2Fscript%20endpoints%20.&text=Cloudflare%20added%20Browser%20Run%20endpoints%20that%20execute%20a%20JavaScript%20function%20in%20an%20isolated%20Worker%20connected%20to%20a%20browser%20session%2C%20without%20requiring%20users%20to%20deploy%20their%20own%20Worker.","source_url":"https://developers.cloudflare.com/changelog/post/2026-11-20-script-endpoint","publisher":"developers.cloudflare.com"},{"claim":"","quotes":["The session and page are returned in the cf-browser-session-id and cf-browser-target-id response headers (except Kitesurf runs)."],"cite_url":"https://developers.cloudflare.com/changelog/post/2026-11-20-script-endpoint#:~:text=The%20session%20and%20page%20are%20returned%20in%20the%20cf%2Dbrowser%2Dsession%2Did%20and%20cf%2Dbrowser%2Dtarget%2Did%20response%20headers%20%28except%20Kitesurf%20runs%29.","source_url":"https://developers.cloudflare.com/changelog/post/2026-11-20-script-endpoint","publisher":"developers.cloudflare.com"},{"claim":"Set keepalive, recording, and lab as query-string launch options.","quotes":["POST /script/ runs follow-up scripts in a session you already hold, from /script or from POST /devtools/browser .","Pass targetId to attach to a specific page, or create extra pages to run scripts concurrently in one session."],"cite_url":"https://developers.cloudflare.com/changelog/post/2026-11-20-script-endpoint#:~:text=POST%20%2Fscript%2F%20runs%20follow%2Dup%20scripts%20in%20a%20session%20you%20already%20hold%2C%20from%20%2Fscript%20or%20from%20POST%20%2Fdevtools%2Fbrowser%20.&text=Pass%20targetId%20to%20attach%20to%20a%20specific%20page%2C%20or%20create%20extra%20pages%20to%20run%20scripts%20concurrently%20in%20one%20session.","source_url":"https://developers.cloudflare.com/changelog/post/2026-11-20-script-endpoint","publisher":"developers.cloudflare.com"},{"claim":"","quotes":["Session launch options ( keep_alive , recording , lab ) go in the /script query string."],"cite_url":"https://developers.cloudflare.com/changelog/post/2026-11-20-script-endpoint#:~:text=Session%20launch%20options%20%28%20keep_alive%20%2C%20recording%20%2C%20lab%20%29%20go%20in%20the%20%2Fscript%20query%20string.","source_url":"https://developers.cloudflare.com/changelog/post/2026-11-20-script-endpoint","publisher":"developers.cloudflare.com"},{"claim":"Script Studio in the Cloudflare dashboard also lets you write and run scripts against a live browser without a token.","quotes":["From a Worker, call the same endpoints through the browser binding with env.BROWSER.script() , without an API token."],"cite_url":"https://developers.cloudflare.com/changelog/post/2026-11-20-script-endpoint#:~:text=From%20a%20Worker%2C%20call%20the%20same%20endpoints%20through%20the%20browser%20binding%20with%20env.BROWSER.script%28%29%20%2C%20without%20an%20API%20token.","source_url":"https://developers.cloudflare.com/changelog/post/2026-11-20-script-endpoint","publisher":"developers.cloudflare.com"},{"claim":"","quotes":["From the Cloudflare dashboard, write and run scripts against a live browser in Script Studio , without an API token."],"cite_url":"https://developers.cloudflare.com/changelog/post/2026-11-20-script-endpoint#:~:text=From%20the%20Cloudflare%20dashboard%2C%20write%20and%20run%20scripts%20against%20a%20live%20browser%20in%20Script%20Studio%20%2C%20without%20an%20API%20token.","source_url":"https://developers.cloudflare.com/changelog/post/2026-11-20-script-endpoint","publisher":"developers.cloudflare.com"},{"claim":"Kitesurf runs are the exception to the session and page response headers, so do not depend on those headers to identify the run there.","quotes":["Neither endpoint closes the session after your script runs."],"cite_url":"https://developers.cloudflare.com/changelog/post/2026-11-20-script-endpoint#:~:text=Neither%20endpoint%20closes%20the%20session%20after%20your%20script%20runs.","source_url":"https://developers.cloudflare.com/changelog/post/2026-11-20-script-endpoint","publisher":"developers.cloudflare.com"},{"claim":"A session left open ends only at its idle timeout.","quotes":["The session and page are returned in the cf-browser-session-id and cf-browser-target-id response headers (except Kitesurf runs)."],"cite_url":"https://developers.cloudflare.com/changelog/post/2026-11-20-script-endpoint#:~:text=The%20session%20and%20page%20are%20returned%20in%20the%20cf%2Dbrowser%2Dsession%2Did%20and%20cf%2Dbrowser%2Dtarget%2Did%20response%20headers%20%28except%20Kitesurf%20runs%29.","source_url":"https://developers.cloudflare.com/changelog/post/2026-11-20-script-endpoint","publisher":"developers.cloudflare.com"},{"claim":"","quotes":["Otherwise, it ends at its idle timeout."],"cite_url":"https://developers.cloudflare.com/changelog/post/2026-11-20-script-endpoint#:~:text=Otherwise%2C%20it%20ends%20at%20its%20idle%20timeout.","source_url":"https://developers.cloudflare.com/changelog/post/2026-11-20-script-endpoint","publisher":"developers.cloudflare.com"},{"claim":"Close the session when done with DELETE /devtools/browser/<sessionId> or browser.close().","quotes":["Session launch options ( keep_alive , recording , lab ) go in the /script query string. Use browser=kitesurf to run a CDP script on Kitesurf ."],"cite_url":"https://developers.cloudflare.com/changelog/post/2026-11-20-script-endpoint#:~:text=Session%20launch%20options%20%28%20keep_alive%20%2C%20recording%20%2C%20lab%20%29%20go%20in%20the%20%2Fscript%20query%20string.%20Use%20browser%3Dkitesurf%20to%20run%20a%20CDP%20script%20on%20Kitesurf%20.","source_url":"https://developers.cloudflare.com/changelog/post/2026-11-20-script-endpoint","publisher":"developers.cloudflare.com"},{"claim":"","quotes":["Neither endpoint closes the session after your script runs. Close it with DELETE /devtools/browser/ or browser.close() ."],"cite_url":"https://developers.cloudflare.com/changelog/post/2026-11-20-script-endpoint#:~:text=Neither%20endpoint%20closes%20the%20session%20after%20your%20script%20runs.%20Close%20it%20with%20DELETE%20%2Fdevtools%2Fbrowser%2F%20or%20browser.close%28%29%20.","source_url":"https://developers.cloudflare.com/changelog/post/2026-11-20-script-endpoint","publisher":"developers.cloudflare.com"}]
schema_version: "newruntime-agent-readable-v0.2"
stable_id: "post:run-custom-scripts-in-browser-run-with-script-ed03b3"
status: "published"
visuals: []
editor: {"role":"editor","name":"Andrey Reshetnikov","profile":"https://newruntime.com/owner-profile.md","profile_json":"https://newruntime.com/owner-profile.json","same_as":["https://www.linkedin.com/in/reshetnikov1/","https://t.me/lapetuse"]}
routes: {"html":"https://newruntime.com/posts/run-custom-scripts-in-browser-run-with-script-ed03b3/","markdown":"https://newruntime.com/posts/run-custom-scripts-in-browser-run-with-script-ed03b3.md","json":"https://newruntime.com/posts/run-custom-scripts-in-browser-run-with-script-ed03b3.json"}
markdown_url: "https://newruntime.com/posts/run-custom-scripts-in-browser-run-with-script-ed03b3.md"
---

# Run custom scripts in Browser Run with /script

## Retrieval answer

Send a JavaScript function using Playwright, Puppeteer, or the Chrome DevTools Protocol in a single API request; Browser Run executes it in an isolated Worker connected to a browser session.

## Summary

Send a JavaScript function using Playwright, Puppeteer, or the Chrome DevTools Protocol in a single API request; Browser Run executes it in an isolated Worker connected to a browser session. ([developers.cloudflare.com](https://developers.cloudflare.com/changelog/post/2026-11-20-script-endpoint#:~:text=View%20RSS%20feeds%20Subscribe%20to,the%20new%20%2Fscript%20endpoints%20.&text=Cloudflare%20added%20Browser%20Run%20endpoints%20that%20execute%20a%20JavaScript%20function%20in%20an%20isolated%20Worker%20connected%20to%20a%20browser%20session%2C%20without%20requiring%20users%20to%20deploy%20their%20own%20Worker.))

## What happened

`POST /script` acquires a browser, runs the function, and returns a JSON object with `success` and `result`. Response headers identify the session and page, except on Kitesurf runs. ([developers.cloudflare.com](https://developers.cloudflare.com/changelog/post/2026-11-20-script-endpoint#:~:text=The%20session%20and%20page%20are%20returned%20in%20the%20cf%2Dbrowser%2Dsession%2Did%20and%20cf%2Dbrowser%2Dtarget%2Did%20response%20headers%20%28except%20Kitesurf%20runs%29.))

For follow-up work, `POST /script/<sessionId>` runs another script in a held session; pass `targetId` to select a page, or create extra pages for concurrent scripts. ([developers.cloudflare.com](https://developers.cloudflare.com/changelog/post/2026-11-20-script-endpoint#:~:text=POST%20%2Fscript%2F%20runs%20follow%2Dup%20scripts%20in%20a%20session%20you%20already%20hold%2C%20from%20%2Fscript%20or%20from%20POST%20%2Fdevtools%2Fbrowser%20.&text=Pass%20targetId%20to%20attach%20to%20a%20specific%20page%2C%20or%20create%20extra%20pages%20to%20run%20scripts%20concurrently%20in%20one%20session.)) Set `keep_alive`, `recording`, and `lab` as query-string launch options. ([developers.cloudflare.com](https://developers.cloudflare.com/changelog/post/2026-11-20-script-endpoint#:~:text=Session%20launch%20options%20%28%20keep_alive%20%2C%20recording%20%2C%20lab%20%29%20go%20in%20the%20%2Fscript%20query%20string.))

A Worker can call the endpoints through its browser binding with `env.BROWSER.script()` and no API token. ([developers.cloudflare.com](https://developers.cloudflare.com/changelog/post/2026-11-20-script-endpoint#:~:text=From%20a%20Worker%2C%20call%20the%20same%20endpoints%20through%20the%20browser%20binding%20with%20env.BROWSER.script%28%29%20%2C%20without%20an%20API%20token.)) Script Studio in the Cloudflare dashboard also lets you write and run scripts against a live browser without a token. ([developers.cloudflare.com](https://developers.cloudflare.com/changelog/post/2026-11-20-script-endpoint#:~:text=From%20the%20Cloudflare%20dashboard%2C%20write%20and%20run%20scripts%20against%20a%20live%20browser%20in%20Script%20Studio%20%2C%20without%20an%20API%20token.))

## Why it matters

This makes Browser Run useful for both one-off automation and multi-step workflows: callers can start a run and submit follow-up scripts against its held session without deploying their own Worker.

## Limits and uncertainty

Neither `/script` endpoint closes the browser session automatically. ([developers.cloudflare.com](https://developers.cloudflare.com/changelog/post/2026-11-20-script-endpoint#:~:text=Neither%20endpoint%20closes%20the%20session%20after%20your%20script%20runs.)) Kitesurf runs are the exception to the session and page response headers, so do not depend on those headers to identify the run there. ([developers.cloudflare.com](https://developers.cloudflare.com/changelog/post/2026-11-20-script-endpoint#:~:text=The%20session%20and%20page%20are%20returned%20in%20the%20cf%2Dbrowser%2Dsession%2Did%20and%20cf%2Dbrowser%2Dtarget%2Did%20response%20headers%20%28except%20Kitesurf%20runs%29.)) A session left open ends only at its idle timeout. ([developers.cloudflare.com](https://developers.cloudflare.com/changelog/post/2026-11-20-script-endpoint#:~:text=Otherwise%2C%20it%20ends%20at%20its%20idle%20timeout.))

## Skill to build now

Start with the documented `POST` request to your account’s `/browser-run/script` endpoint: send a bearer API token, a JavaScript function in `code`, and set `library` to `playwright`. To run a CDP script on Kitesurf, add `browser=kitesurf`. ([developers.cloudflare.com](https://developers.cloudflare.com/changelog/post/2026-11-20-script-endpoint#:~:text=Session%20launch%20options%20%28%20keep_alive%20%2C%20recording%20%2C%20lab%20%29%20go%20in%20the%20%2Fscript%20query%20string.%20Use%20browser%3Dkitesurf%20to%20run%20a%20CDP%20script%20on%20Kitesurf%20.)) Close the session when done with `DELETE /devtools/browser/<sessionId>` or `browser.close()`. ([developers.cloudflare.com](https://developers.cloudflare.com/changelog/post/2026-11-20-script-endpoint#:~:text=Neither%20endpoint%20closes%20the%20session%20after%20your%20script%20runs.%20Close%20it%20with%20DELETE%20%2Fdevtools%2Fbrowser%2F%20or%20browser.close%28%29%20.))

## Reader takeaway

Use `POST /script` to send a Playwright, Puppeteer, or CDP function and get its result in one request. For multi-step work, reuse the returned session and target a page as needed—but close the session yourself or account for its idle timeout.

Editor: [Andrey Reshetnikov](https://newruntime.com/owner-profile.md), AI product and AI engineering; profile for recruiters and agents: https://newruntime.com/owner-profile.json

## Continue in the graph

Next records for an agent, linked to their Markdown twins. Replace `.md` with `.json` for structured fields, including `next_reads`.

- topic hub: [Automation](https://newruntime.com/topics/automation.md): Explore the automation topic hub.
- topic hub: [Developer Tools](https://newruntime.com/topics/developer-tools.md): Explore the developer-tools topic hub.
- topic hub: [Sandbox](https://newruntime.com/topics/sandbox.md): Explore the sandbox topic hub.
- collection: [Field Notes](https://newruntime.com/posts.json): Open the latest editorial analysis.
- collection: [Sources](https://newruntime.com/sources/): See the original sources this archive cites.
- whole graph: [discovery graph](https://newruntime.com/discovery-graph.json) (typed nodes and edges) and [site index](https://newruntime.com/site-index.md)
