PARAS MADAN
All writing

Latest in AI

Run a read-only browser check with Cloudflare Browser Run

Use Cloudflare Browser Run's new script endpoint to check an owned staging page, return a small result to an agent, and close the browser before it keeps billing.

A release assistant can know that a deployment finished without knowing whether the new version actually appeared in the browser. If the answer lives in a component that renders after the page loads, checking the initial HTML can miss it.

Cloudflare's November 20 Browser Run update adds a way to run a custom browser script through an API call without deploying a Worker. For an AI workflow, the useful first step is to give the assistant one narrow, read-only check, not a browser it can direct anywhere.

Choose the smallest browser interface

If you only need HTML or a screenshot from a URL, start with a Quick Action. Use a custom script when you need a sequence the action does not cover. For example, load a staging page, wait for its version badge to render and read the value.

Decide what the check should return before writing its script. A release assistant needs to know which build is showing and whether the page was readable. It does not need the complete page text, cookies or a screenshot of the rest of the site.

Try it on a staging page you own

In the Cloudflare dashboard, choose Browser Run > Script Studio, select Playwright and try a function like this. Replace the placeholder URL and selector with a staging page and a visible build badge you control.

async ({ page }) => {
  const response = await page.goto("https://staging.example.com/release", {
    waitUntil: "domcontentloaded",
    timeout: 10000
  });
  if (!response?.ok()) {
    return { observed: false, reason: "page_not_ready" };
  }
  const badge = page.locator("[data-build-id]");
  await badge.waitFor({ state: "visible", timeout: 5000 });
  const build = (await badge.innerText({ timeout: 5000 })).trim();
  return { observed: Boolean(build), build };
}

Check the returned build against your deployment record outside the browser. A page responding with HTTP 200 is not enough: the app could be serving the previous build. Try the check against both a known build and a fixture where you deliberately remove the badge.

Expose a fixed check, not a script runner

When the prototype is useful, move it behind a named tool such as check_staging_build. Store the source code and the URL in the application. Give the agent the expected build ID if it needs to compare results, but do not give it an input field for JavaScript, arbitrary URLs or selectors.

For the REST version, send the fixed function as the code string in POST /script with library: "playwright". The custom scripts guide specifies the Browser Run - Edit permission for API tokens. Keep the token server-side. If this app already runs on Workers, the browser binding also provides env.BROWSER.script() without having to pass a REST token.

Have the calling application distinguish three outcomes: the expected build is visible, a different build is visible, or the check could not complete. Report that last outcome as unknown rather than approving or rejecting the release on missing evidence.

Give each layer its own timeout

Cloudflare's script-wide timeout does not include browser acquisition. It also does not override Playwright's own calls. If the script reaches its cap first, the endpoint returns 408. A Playwright timeout that throws first can surface as 422. Set the navigation and selector deadlines below the script cap, and allow the calling service to account for acquisition too.

A missing badge and a browser service delay may both leave you without a build ID, but they need different fixes. Record the failure category before deciding whether to run the check again.

Close the browser before calling it done

For a standard browser session, save the cf-browser-session-id header. You can reuse that session with POST /script/<sessionId>, but one release check rarely needs it. Close it via the session management endpoint when finished, including after errors that return a session ID. In Script Studio, use Close browser.

The Browser Run pricing page includes browser time and concurrency for custom browser sessions. Workers Paid includes 10 browser hours per month, then bills $0.09 per additional hour, with separate concurrency pricing. Script completion does not end a standard session, so make cleanup part of the tool rather than leaving it to the assistant.

Turn an API release into a usable workflow

I'm Paras. I work at the intersection of AI, engineering and distribution.

I help AI and developer tool teams explain what shipped, how to try it and what to check before putting it into production.

Book a 30-minute call.