feat: add Cloudflare Containers as alternative browser provider#1
Open
dcartertwo wants to merge 2 commits intomainfrom
Open
feat: add Cloudflare Containers as alternative browser provider#1dcartertwo wants to merge 2 commits intomainfrom
dcartertwo wants to merge 2 commits intomainfrom
Conversation
Add a drop-in Cloudflare Browser Rendering backend alongside BrowserBase, selectable via BROWSER_PROVIDER env var. Key changes: - Refactor browser.ts into provider factory with browserbase/cloudflare providers - Add Cloudflare Worker + Durable Object (worker/) to hold persistent browser sessions - Extract shared DOM walker into page-extract.ts - Add screenshot preview fallback in BrowserPreview (no live iframe for CF) - Add retry with backoff, 429 handling, and session expiry detection - Update README and .env.example with both provider paths The BrowserBase path remains fully functional and is the default.
Replace the Durable Object + @cloudflare/playwright approach with Cloudflare Containers running standard Playwright + system Chromium. This avoids the bot-detection headers that Browser Rendering injects (cf-biso-devtools, Signature-agent) which caused every request to be flagged by Cloudflare's own bot protection. - Add Docker container with Node.js HTTP server + system Chromium - Add stealth module (navigator.webdriver, plugins, chrome.runtime, etc.) - Replace LoginBrowserDO with LoginBrowserContainer (extends Container) - Rewrite worker to use getContainer() instead of DO fetch - Update wrangler.jsonc with containers config (standard-2, 6GB RAM) - All 21/23 bot.sannysoft.com tests pass (2 WebGL failures expected)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add Cloudflare Containers as a drop-in alternative to BrowserBase for running headless browser sessions. Selectable via
BROWSER_PROVIDER=cloudflareenv var.Why Containers instead of Browser Rendering?
We initially built on Cloudflare Browser Rendering (Durable Object +
@cloudflare/playwright), but every request was flagged as a bot because Browser Rendering injects automatic headers (cf-biso-devtools,Signature-agent, etc.) that cannot be removed. Sites with Cloudflare bot protection (Turnstile, managed challenges) blocked us immediately.Cloudflare Containers runs standard Chromium with standard Playwright inside Docker containers on Cloudflare's edge — no bot-detection headers injected.
Architecture
What's included
Next.js app changes:
BROWSER_PROVIDER=browserbase|cloudflare)providers/browserbase.tsproviders/cloudflare.ts(retry with backoff, 429 handling,SessionExpiredError)BrowserSessionabstraction — all browser functions take session instead of page<img>fallback when noliveViewUrl)Worker + Container:
worker/src/index.ts— Worker usinggetContainer()for session routingworker/src/login-browser-container.ts— Container class (standard-2, 15min sleep)worker/container/src/server.ts— Node.js HTTP server with all browser operationsworker/container/src/stealth.ts— Stealth patches (21/23 bot tests pass)worker/Dockerfile—node:22-slim+ system chromium (~357MB image)Stealth results (bot.sannysoft.com)
Testing performed
npm run build— zero errorstsc --noEmit— zero errorswrangler deploy— container deployed successfullycredential_login_formwith 2 inputs + submit button)Environment variables