Tech Insights

Cloudflare Browser Run’s /script Endpoint: Why Custom Playwright Automation No Longer Needs a Worker

Browser automation usually becomes complicated at the moment a script needs more than one action. Opening a page is easy. Opening it, waiting for a client-rendered table, clicking a filter, preserving cookies, and returning…

Browser automation usually becomes complicated at the moment a script needs more than one action. Opening a page is easy. Opening it, waiting for a client-rendered table, clicking a filter, preserving cookies, and returning structured data requires a browser session, an automation library, and somewhere to run the code.

Cloudflare’s new /script endpoints for Browser Run move that execution surface into a single API request. Announced on 20 November 2026, the feature lets developers submit JavaScript written for Playwright, Puppeteer, or the Chrome DevTools Protocol. Browser Run acquires an isolated browser session, connects the script to it, and returns the script’s result without requiring a separate Worker deployment.

The meaningful change is not that browser automation exists in the cloud. It is that the custom code can now be the request payload rather than another service the team must deploy, connect, and maintain.

From a browser task to a browser workflow

Cloudflare’s earlier quick actions are useful for common tasks such as screenshots, PDFs, and simple extraction. A real workflow often needs state:

  1. Navigate to a page.
  2. Wait for a client-side component to load.
  3. Click a control or fill a form.
  4. Read the resulting page.
  5. Return only the fields the next system needs.

In the past, a team could run Playwright or Puppeteer in its own service, manage browser binaries, and expose an internal endpoint for the automation. Cloudflare’s official changelog entry says the new /script endpoint runs the submitted function in an isolated Worker connected to a Browser Run session. The team supplies the workflow; Cloudflare supplies the browser session.

A concrete example: extracting a filtered report

Imagine a monitoring job that needs a report from a dashboard that does not expose the required view through a simple URL. The report is behind a filter and a client-side table. A custom Playwright script can navigate to the dashboard, wait for the table, select the desired period, click “Apply,” and return the rows as JSON.

The browser actions remain ordinary Playwright actions. What changes is where they run. Instead of building a long-lived automation service, the caller can send a function such as:

async ({ page }) => {
  await page.goto("https://example.com/report");
  await page.getByRole("button", { name: "Apply" }).click();
  return await page.locator("table tr").allTextContents();
}

Cloudflare’s documentation says the function can run with Playwright, Puppeteer, or CDP. A REST request can create a new session, while a follow-up request can run another script in an existing session. That makes a multi-step workflow possible without passing cookies or page state through every request in the caller’s own application.

Two ways to call it

The first path is the REST API. A request to the /script endpoint creates a browser session, runs the submitted JavaScript, and returns session identifiers in response headers. A later request to /script/<sessionId> can reuse that session for follow-up actions.

The second path is a Cloudflare Worker with a browser binding. Cloudflare’s custom scripts documentation describes an env.BROWSER.script() call that uses the binding instead of an API token. The dashboard’s Script Studio provides another entry point: developers can write and run scripts against a live browser without first setting up a token or Worker.

Those entry points serve different team preferences. REST is useful when an existing service already owns scheduling, queues, or result storage. A Worker binding keeps the orchestration close to other Cloudflare code. Script Studio is useful for exploring a selector or workflow before it becomes an application dependency.

Session state is useful, but it is not free

Follow-up scripts can share pages, cookies, and navigation history in the same session. That is valuable for login flows, multi-page forms, and workflows that need a browser to remember the previous step.

State also creates lifecycle work. Cloudflare says sessions have an idle timeout, configurable through keep_alive, and that sessions should be closed when the workflow is complete. A session that remains open consumes browser time until it is closed or reaches its idle timeout. A short script should not leave a long-lived browser session running simply because another step might be needed later.

The practical pattern is to decide whether the workflow is one request or a session. Use a new session for a self-contained capture or extraction. Reuse a session when the state is part of the workflow, then explicitly close it after the final action.

Where the trade-offs appear

Moving browser execution to an API reduces infrastructure maintenance, but it does not eliminate automation fragility. Selectors can change, a page can return a different layout, and a navigation can take longer than the default timeout. Cloudflare documents a maximum script timeout and notes that Playwright or Puppeteer navigation defaults can fire before the overall run limit.

Security boundaries also remain important. A script that can log in, fill forms, or click through an account should receive only the session context and credentials it needs. Results should be treated as data returned by an automation, not as proof that a page was correct. Sensitive values should not be returned in logs or stored in a result object unless the workflow requires them.

There is a cost and capacity dimension too. Browser time, session concurrency, rate limits, and the time needed to render a page can dominate a workflow that looks tiny in code. A short, deterministic script is easier to measure than a general-purpose crawler that keeps a browser alive while it waits for uncertain conditions.

A sensible adoption path

  1. Prototype the workflow in Script Studio and identify stable selectors.
  2. Return a small JSON object rather than a full page or screenshot when the caller needs structured data.
  3. Set explicit navigation and script timeouts for the slowest expected page.
  4. Choose REST or a Worker binding based on where scheduling and secrets already live.
  5. Close sessions deliberately and record browser time, failures, and result quality.

Cloudflare Browser Run’s /script endpoint is best understood as a smaller deployment boundary for browser workflows. It lets teams keep the code that expresses the user journey while delegating the browser lifecycle to a managed service. The memorable question is no longer “Where will we host a browser?” It is “Which browser steps are worth turning into a short, observable function?”

This article is a general information summary based on the cited public sources. It is not legal, cybersecurity, or compliance advice.

Written By

Shaik Sai Meera Editorial Team

shares practical publishing insights, comparisons, and WordPress-focused growth guidance for modern web teams.

173 articles published