Programming
Cloudflare Browser Run Adds a /script API: Run Playwright Without Deploying a Worker
Cloudflare's new /script endpoint runs custom browser automation without a deployed Worker. It also introduces an easy-to-miss responsibility: browser sessions stay alive until you close them or they time out.
You need to open a webpage, click a button, extract some information, and return the result to another application.
Playwright can do all of that. The more interesting question is where the browser should run.
You could maintain a local browser environment, use a remote browser through Chrome DevTools Protocol, or deploy a Cloudflare Worker with a browser binding.
But what if the entire operation could be submitted as an ordinary HTTP request?
On November 20, 2026, Cloudflare introduced new /script endpoints for Browser Run.
The endpoints accept JavaScript functions written for Playwright, Puppeteer, or Chrome DevTools Protocol (CDP). Cloudflare executes the function in an isolated Worker connected to a remote browser and returns its result.
You no longer need to deploy your own Worker merely to execute a custom browser script.
There is, however, an important detail that becomes apparent when you look beyond the initial request: the browser session does not automatically close after the script finishes.
That affects both how applications reuse sessions and how Browser Run usage is billed.
What changed from the previous approach?
Cloudflare Browser Run already supported remote browser automation before this announcement.
Developers could create browser sessions through the API, connect using CDP, and control the browser with Playwright or Puppeteer.
It was also possible to use browser bindings inside deployed Cloudflare Workers.
The new endpoint changes how the automation code reaches the browser.
Instead of managing a separate connection to a remote browser, you can submit the function itself.
For example:
async ({ page }) => {
await page.goto("https://example.com");
return {
title: await page.title(),
heading: await page.locator("h1").textContent()
};
}
Cloudflare receives that function, executes it against a browser page, and returns the resulting data.
The relevant differences are:
| Approach | How it works |
|---|---|
| Existing CDP browser session | Create a session and connect a client that sends browser commands |
| Worker with browser binding | Deploy a Worker that controls Browser Run |
New /script endpoint |
Submit the automation function through an HTTP request |
| Script Studio | Write and execute scripts from Cloudflare Dashboard |
The new endpoint does not replace CDP or browser bindings.
It provides another way to use the same remote-browser infrastructure, particularly when a task is easier to express as one JavaScript function than as a separately managed browser client.
Running Playwright through one HTTP request
The new endpoint is:
POST https://api.cloudflare.com/client/v4/accounts/{accountId}/browser-run/script
To use the REST API, you need a Cloudflare account and an API token with the documented Browser Run — Edit permission.
The request also needs your Cloudflare Account ID.
Here is a minimal example using cURL:
curl -i -X POST \
"https://api.cloudflare.com/client/v4/accounts/<accountId>/browser-run/script" \
-H "Authorization: Bearer <apiToken>" \
-H "Content-Type: application/json" \
-d '{
"library": "playwright",
"code": "async ({ page }) => { await page.goto(\"https://example.com\"); return { title: await page.title(), heading: await page.locator(\"h1\").textContent() }; }"
}'
The library property selects the automation interface.
In this case, Cloudflare provides a Playwright page object to the function.
The script navigates to example.com, retrieves the document title and first heading, and returns a JavaScript object.
A successful response has this structure:
{
"success": true,
"result": {
"title": "Example Domain",
"heading": "Example Domain"
}
}
The response also includes headers identifying the created browser session:
cf-browser-session-id: <session-id>
cf-browser-target-id: <target-id>
These identifiers matter if the application intends to continue interacting with the same browser.
The command above uses Unix-style shell quoting. PowerShell users may need different escaping or can construct the JSON request body using PowerShell’s native HTTP tools.
Also, the API token belongs in a trusted environment. It should not be embedded in public frontend JavaScript, where visitors could extract it.
Running another script in the same browser
Suppose the first script opens a website and navigates to a particular page.
You then need to perform another action.
Launching a new browser would discard the current page and session context.
Cloudflare provides a second endpoint for this:
POST /client/v4/accounts/{accountId}/browser-run/script/{sessionId}
The session ID comes from the previous response.
For example:
curl -X POST \
"https://api.cloudflare.com/client/v4/accounts/<accountId>/browser-run/script/<sessionId>" \
-H "Authorization: Bearer <apiToken>" \
-H "Content-Type: application/json" \
-d '{
"library": "playwright",
"targetId": "<target-id>",
"code": "async ({ page }) => ({ url: page.url(), title: await page.title() })"
}'
This request attaches to an existing browser session rather than acquiring another one.
It can also target the page created during the first call.
That makes it possible to divide a longer workflow into several requests.
For example, one script could navigate to a dashboard, another could open a report, and a third could extract the required information.
The session can preserve pages, cookies, and navigation history between these calls.
There is one limitation worth remembering: additional browser contexts created with browser.newContext() are closed after the script execution. Pages in the session’s default context can persist.
So the system supports continued browser interaction, but not every resource created inside a script necessarily survives the request.
What happens if two scripts use the same page?
Session reuse also introduces a concurrency problem.
Suppose two requests run simultaneously against the same page.
One attempts to navigate to another URL.
The other tries to click an element on the original page.
Cloudflare does not automatically serialize requests targeting the same browser page.
The operations can interfere with each other.
If several scripts need to run concurrently within one browser session, Cloudflare recommends creating separate page targets and assigning the appropriate targetId to each run.
For sequential operations, keeping them in one script or coordinating requests from the calling application may be simpler.
This is particularly relevant when building automation that receives several jobs at once.
A shared browser session does not imply that all its scripts execute in a safe, predetermined order.
The browser remains open after the script finishes
This is probably the most important operational detail in the announcement.
Consider the first request.
It opens a webpage, reads the title, and returns a successful response.
The HTTP request is complete.
But the browser session is still running.
According to Cloudflare’s documentation, neither /script nor /script/{sessionId} automatically closes an existing session after the script starts.
This remains true if the script succeeds, throws an exception, times out, or encounters a compilation error.
The exception is a failure that occurs after Cloudflare acquires a browser but before the script begins. In that situation, Cloudflare closes the session because the caller never received its ID.
For ordinary script execution, session cleanup is the caller’s responsibility.
To close a session through the API:
curl -X DELETE \
"https://api.cloudflare.com/client/v4/accounts/<accountId>/browser-run/devtools/browser/<sessionId>" \
-H "Authorization: Bearer <apiToken>"
Alternatively, a script can call browser.close() when finished.
If neither happens, the browser remains available until its idle timeout.
The default idle timeout is 60 seconds.
It can be configured using the keep_alive parameter when creating the session, within Cloudflare’s documented limits.
Why does this matter?
Because Browser Run measures browser time across the lifetime of the session, not merely the few seconds spent executing JavaScript.
Imagine a script that finishes in two seconds.
If the browser remains idle for another minute before closing, that additional session lifetime still contributes to browser usage.
The response includes the X-Browser-Ms-Used header, reporting cumulative browser time since the session began.
That value is useful for monitoring, but the session may continue consuming browser time after the response is returned.
An application that creates many short-lived sessions without explicitly closing them can therefore consume more browser time than its script execution times suggest.
Is Browser Run free?
Browser Run supports both free and paid Cloudflare plans, but usage is limited and billing depends on the method.
As documented on November 20, 2026:
| Resource | Workers Free | Workers Paid |
|---|---|---|
| Browser time included | 10 minutes/day | 10 hours/month |
| Concurrent browser allowance | 3 | 10, measured using monthly average daily peak usage |
| Additional browser time | Subject to free-plan limits | $0.09/hour |
| Additional concurrent browsers | Subject to free-plan limits | $2 per additional browser under the documented calculation |
Custom scripts using browser sessions fall under Browser Run’s browser-time and concurrent-browser model.
The new HTTP interface does not make remote browser execution free of infrastructure costs.
But it can reduce the amount of infrastructure code a developer must maintain.
There are also execution limits.
Cloudflare currently documents a 10 MiB request-body limit and a default script timeout of 60 seconds, configurable up to 120 seconds.
Long-running automation must take those limits into account.
A script that needs considerably more time may require splitting the work into several requests against the same session or reconsidering how the automation is organized.
Script Studio removes even the initial API setup
For developers who want to experiment before writing an HTTP client, Cloudflare also introduced Script Studio.
It is available from the Browser Run area of Cloudflare Dashboard.
You can select an automation library, write a script, and execute it against a live remote browser.
Script Studio displays the result alongside a live browser view.
No separately deployed Worker or manually created API token is required for this dashboard workflow.
It is useful when testing a selector, checking how a webpage behaves, or trying a sequence of interactions before integrating it into an application.
But Script Studio does not remove Browser Run’s usage limits or session-lifecycle considerations.
The browser still exists as a managed resource, and Cloudflare provides a control to close it.
When is the new API actually useful?
The /script endpoint is particularly suitable when another application already knows what browser operation it wants to perform.
A backend might need to inspect a page after JavaScript has rendered it.
A scheduled job might need to navigate through several screens before collecting a report.
A testing utility might need to reproduce a browser interaction without provisioning a local browser.
Previously, developers could accomplish these tasks using Cloudflare’s existing browser-control interfaces.
The new endpoint makes the integration smaller.
A request contains a function.
Cloudflare executes it.
The response contains the result and, when applicable, identifiers for continuing the session.
However, the simplicity of the API should not obscure what the script can do.
Browser automation can navigate to websites, interact with accounts, and operate on information visible to the browser.
Applications accepting user-supplied scripts or target URLs need appropriate access controls, input restrictions, and safeguards around credentials.
And applications that reuse sessions must consider whether the data retained in one browser session should be accessible to another job or user.
Session reuse is convenient, but it should be intentional.
What changed on November 20?
Cloudflare did not invent remote Playwright execution on November 20.
Browser Run already supported remote browser sessions and connections through CDP.
What changed is the way developers can submit custom automation.
The new /script API removes the need to deploy a Worker or maintain a separate CDP client for workflows that fit into submitted JavaScript functions.
It also makes several browser interactions possible within one HTTP request.
For longer workflows, /script/{sessionId} allows the application to continue using an existing browser.
That convenience comes with one responsibility: the caller owns the browser session’s lifetime.
When the automation is finished, closing the browser is part of finishing the task.
Otherwise, a request that took only a moment to execute can leave a browser consuming time long after its result has been returned.
That detail is easy to miss when focusing on the new endpoint. Yet it may matter more in production than the reduction in setup code.