PuppyIP Resource Center
AI Tool Troubleshooting 5 min Published 2026-11-23

Cloudflare Browser Run /script guide: sessions, timeouts, and cleanup

Cloudflare launched Browser Run custom scripts in beta on November 20. Use /script when a browser check needs several interactions, such as opening a page, clicking a control, and checking the resulting state. Save the session and target IDs if you plan to continue on that page with /script/<sessionId>.

Cloudflare Browser Run Playwright Puppeteer Browser QA

Service eligibility and regional restrictions

PuppyIP serves only compliant overseas businesses and their authorized personnel. Proxy services are not available in mainland China. The service may only be used for lawful business activities outside mainland China. Use of this service within mainland China is prohibited.

Hosting a proxy IP or server overseas does not change these restrictions. The service must not be provided to end users in mainland China through relaying, forwarding, sharing or resale. Before use, read the Terms of Service.

Key Takeaways

  • Use a Quick Action such as /snapshot when one load can deliver the screenshot, HTML, or links you need.
  • Start the workflow with /script and continue with /script/<sessionId>. Close the session when finished, since browser time follows the session's lifetime.
  • For 408 and 422 errors, check the whole-script timeout, the library's navigation or wait timeout, and the error thrown inside the function.

Choose a Quick Action or a custom script

For a single load of a page you own, check whether /snapshot returns the outputs you need, such as a screenshot and links. Use a custom script when the check requires switching tabs, waiting for content to change, and then reading its new state. REST calls use an API token with Browser Run - Edit. A Worker with a Browser Run binding can call that binding.

Standard sessions can run Playwright, Puppeteer, or raw CDP. A Playwright check can open a test page, click your own UI control, and read the result within one function. Return a serializable check result. Verify the returned value, such as whether a title matched the expectation, before recording the page check as passed.

Save both IDs to continue on the same page

A standard /script call acquires a session and returns cf-browser-session-id and cf-browser-target-id. Save both with the check. In the follow-up operation, put the session ID in /script/<sessionId> and pass the still-open page's ID as targetId in the request body. Further checks can reuse the page, cookies, and navigation state.

An existing session keeps its original keep_alive setting. An old targetId can return 404 when its page has closed. Check the session and target before deciding whether to open another page or restart the workflow in a fresh session. Parallel runs on one page can change each other's state. Give independent checks separate pages when they need to run concurrently.

Set separate time budgets for 408 and 422

The request body's timeout caps execution of the complete script, in milliseconds. Cloudflare documents a default of 60 seconds and a maximum of 120 seconds. The timer starts with script execution, and your HTTP client needs to allow for browser acquisition too.

Navigation and wait calls inside Playwright or Puppeteer keep their own timeouts. A slow operation interrupted by the overall limit can return 408. A library timeout that throws inside the script can return 422. Compile errors and other exceptions can also produce 422, so read the error message and any detail field. For a navigation that needs 40 seconds, give that call a 40-second limit and leave a larger budget for the whole script to handle its result.

Close the browser as part of cleanup

Once a script starts in a standard session, the session can stay open after success, an exception, or a timeout. When you have the session ID, use DELETE /devtools/browser/<sessionId> in your cleanup path so a script timeout can still be followed by a deliberate close. The default idle timeout is 60 seconds. Set keep_alive when acquiring a new session if your workflow needs a different idle interval.

Standard Browser Sessions are metered by session lifetime and concurrency. X-Browser-Ms-Used is the cumulative browser time at the moment of the response. Compare consecutive readings for the same session to estimate the increment. The session can continue accruing time after the last response. Kitesurf requests have separate pricing and a different set of session capabilities.

Sources

Frequently Asked Questions

Why does the SDK return the result without the IDs I need?

Read the underlying HTTP response. Cloudflare documents .withResponse() in the TypeScript SDK and with_raw_response in the Python SDK, then reads both IDs from the response headers.

Why do I still get 404 after passing targetId?

Confirm that the session exists and that the page ID identifies an open page within that same session. Use the new targetId if you created a replacement page. An explicitly closed session can also return 410.