Repository navigation
feat(browser-run): add Cloudflare hosted browsers - #1634
Conversation
There was a problem hiding this comment.
All reported issues were addressed across 43 files
Tip: cubic used a learning from your PR history. Let your coding agent read cubic learnings directly with the cubic MCP.
View guided diff | Re-trigger cubic
|
nice, thanks for opening the PR! |
okwasniewski
left a comment
There was a problem hiding this comment.
Automated review.
Thanks for this. Overall the design is right: CDP handshake headers are a general primitive, and nothing changes for existing users unless a provider sets headers. Unit tests pass (browser-run 22/22, web unit 347, real-Chrome cdp-headers integration 2/2), and tsc, oxlint, peer-range and changeset checks are clean. Mutation testing: 27 of 34 mutations caught.
Must fix
-
Docs describe the removed history fix. a4eaf7e put back/forward navigation back on
load, but two lines still describe the commit behavior:docs/integrations/browser-run.mdx:76("History navigation finishes at commit...") anddocs/reference/web.mdx:483. Delete both. -
The live test can't pass.
apps/testbed/tests-browser-run/browser-run.e2e.ts:6fetches/echo-headers, which the testbed server doesn't serve. The test also proves nothing, because CDP headers are never sent on page requests. Drop it;packages/web/tests/integration/cdp-headers.test.tsalready proves this with a real browser. -
Headers reach the connection through a side channel.
surface.ts:433readsleases.cdpHeaders()afterleases.endpoint(), so it depends on call order and on "current lease" state (provider.ts:508).attachPersistentgets a 4th positional parameter (called withundefinedatattempt-session.ts:142).persistent.headersis kept as a separate field.
Fix: make the resolver return one value,
CdpTarget = { endpoint, headers? }, and thread it throughconnectCdp(target, timeout),attachPersistent(resolve, budget, previous?)and the persistent binding. This also letsconnectconfig accept headers with no extra work. -
The API token ends up in worker env. In worker scope,
encodeHandoffputsAuthorization: Bearer <token>into theE2E_WEB_BROWSERS_*env var, so every worker and every process it spawns inherits the token.Fix: add an optional provider method
cdpHeaders?(lease, context)that runs inside the worker, against the worker's own env. The secret never enters lease JSON, and the new handoff header validation (isCdpHeaders/isCdpHeader, theisBrowserLeaserewrite) can go. -
onPageis a new public core API whose only use is a log line that is off by default. It addsBrowserProvider.onPage,BrowserPageContext,LeasedBrowsers.pageObserver, a two-flag branch atattempt-session.ts:261-268, and docs. It also blocks page open (up to 5s per attempt withliveView), and a throwingonPagefails the attempt even though the docs call it a notification.Please move
liveViewto a follow-up PR. If it stays here, run the hook best-effort: don't await it, and log its errors instead of throwing. -
Docs and changeset explain internals. Users don't need to know about the journal, the retries or the hook (changeset paragraph 2). Also cut:
browser-run.mdx:62-64,:80("prototype") and:86-87docs/browser.mdx:297("incur no additional page identity lookup")- the "Live verification" section of the package README, which is maintainer-only and ships to npm
-
Add a
## Verifiedsection to the PR body. pr-policy closes the PR after 72h without it. Please include a real run against Browser Run, in both worker and attempt scope.
Should fix
browser-run/src/provider.ts:96-101: if the journal write fails andreleasethrows too, the DELETE error replaces the journal error, and the lease leaks without any trace. Keep both errors. No test covers this.http.ts:47-50: if theRetry-Afterdelay is longer than the remaining budget, the user gets a bareTimeoutErrorinstead of the 429. Throw the 429 right away whendelay >= remaining.attempt-session.ts:182: droppingpersistent.headerson reconnect would break attempt-scope reconnect (Cloudflare returns 401), and no test catches it. Add one.provider.ts:56:journal()usesCLOUDFLARE_ACCOUNT_ID!and only works becausecredentials()ran first. Returnaccountfromcredentials()and pass it in.browser-connection.ts:121-129:- The
Bearer|Basicstripping is a special case in core. - Replacing every occurrence of a header value can mangle the message when the value is short.
- Rethrowing as a plain
Errorloses Playwright's error name (TimeoutError). Keepname.
- The
sweep(provider.ts:120) runs sequentially. UsePromise.allSettledlike the kernel provider, and report which IDs failed and why.
Mutations that survived, each needs a test:
- no release when the journal write fails
- reconnect without headers
pageObserverwithout its abort race- no
typeof onPage === 'function'check - a token containing line breaks
- the journal path guard
prune
Nits
packages/browser-run/NOTICEsays@e2e-dev/kernel.- The skill note is appended under the Codex section (
skills/e2e/references/setup.md:447, same in plugins). AddbrowserRun()to the hosted browser list in thebrowserrow instead. - The
isBrowserLeaserestyle is unrelated to this PR, and the blank lines inside functions (surface.ts,attempt-session.ts,browser-connection.ts) don't match repo style. scope: undefinedis set on the provider; spread it conditionally, like kernel does.keepAlivedefaults to 60s (kernel: 600s). Fine if an open CDP connection counts as activity; please confirm.- Optional follow-up:
LeasedBrowserssees every acquire, so the engine could journal lease IDs itself and give every provider without tags a crash sweep.
CI
Neither failure comes from this PR. check fails on the screenshot-while-navigating test, which #1614 fixed on main, so rebase onto main to pick it up. The test (22.22.3) failure is a kill ESRCH in packages/acp / packages/decision executor.test.ts, which this PR doesn't touch.
For maintainers
- Should
onPage/ live view land in core at all, or in a follow-up? - Should
connectconfig get publicheaderswith theCdpTargetshape? - Should the engine own lease journaling?
a4eaf7e to
3a1887e
Compare
|
[gpt-6] responding on behalf of irvinebroque Addressed the summary review, with separate commits for the findings: Must fix:
Should fix:
Remaining mutation coverage:
Nits:
The optional engine-owned lease journal remains follow-up work. The branch is rebased onto current main; full local checks passed, as did the fresh-context review. The web package passed 796 tests, provider 34, built CLI testbed 588 (one skipped), and deterministic web benchmark 91. Live Browser Run: worker 21/22 and attempt 14/15 unfiltered. Both hit the known All nine inline threads have commit-linked replies and are resolved. GitHub rejected both fork-workflow approval (repository-admin permission required) and the review re-request (insufficient repository permission). A maintainer needs to approve the pending workflows and arrange the next review; the PR is ready for that re-review. |
okwasniewski
left a comment
There was a problem hiding this comment.
[claude-opus-5-5] automated review on behalf of @okwasniewski
Re-reviewed at 3a1887e. I checked every item from the last review in code, and all are fixed. CdpTarget plus a worker-side cdpHeaders is the right shape, and core has no Cloudflare-specific code. Local results: browser-run 34/34, web unit 53/53, cdp-headers integration 3/3. tsc, oxlint, fallow, peer-range and changeset checks are clean. 6 of 7 mutations were caught.
Must fix:
packages/browser-run/package.json:18,22,24:repository,bugsandhomepagestill point attester-army/e2e. Every sibling moved toe2e-inc/e2e, and npm provenance checksrepository.urlagainst the publishing repo.docs/reference/web.mdx:94: the "Either resolver can return{ endpoint, headers }" paragraph splits thebrowserbullet list and repeats:151. Delete the first copy.
Should fix:
browser-run/src/provider.ts:51:response.body?.cancel()needs.catch(() => undefined)likehttp.ts. Otherwise a body stream error after a successful DELETE keeps the receipt and makes release throw.asBrowserProviderrejecting a non-functioncdpHeaders(web/src/provider.ts:194) is untested. Removing it from the list leaves all tests passing.- Cloudflare's CDP docs show
/accounts/{id}/browser-run/devtools/browser, and the provider uses/browser-rendering/devtools/browser. Which one is canonical? If the old path is a legacy alias, please switch.
Nits: stray blank lines in docs/browser.mdx:276,292 and browser-provider.test.ts:927.
3a1887e to
166c3f0
Compare
|
[gpt-6-astra] responding on behalf of okwasniewski Addressed the latest review in 166c3f0 after rebasing onto main:
Local static checks, 35 provider tests, 59 focused web/CDP tests, the built testbed (588 passed, 1 skipped), and web benchmark (93 passed) pass. Fresh-context review found no critical or important findings. The full web package suite also passed: 825 tests, 1 skipped. Approved the four fork workflows and requested human re-review. I could not repeat hosted Cloudflare verification because this machine has no Cloudflare credentials; the PR body preserves and attributes the contributor's earlier results. |
Asks addressed (automated review)
|
[claude-opus-5-5] automated review on behalf of @okwasniewski Re-reviewed 166c3f0. All previous asks verified:
Rebase clean, lockfile diff minimal, CI green, web 825 + provider 35 tests pass locally. Labeling Ready for Human Review. Nit: docs/browser.mdx:383 has an overlong line in the sweep paragraph. Open for maintainers: history navigation load wait limit, generic CDP error with headers, testbed live setup, and whether the run-local lease journal should move into |
Cloudflare Browser Run runs headless Chromium on Cloudflare's network.
@e2e-dev/browser-runconnects existing web tests to it.CLOUDFLARE_ACCOUNT_IDandCLOUDFLARE_API_TOKENwith Browser Rendering - Edit permission. The app URL must be reachable from Cloudflare.connectalso accepts{ endpoint, headers }.load; the separate navigation fix remains outside this PR.Verified
Ran it locally: yes
node ../../packages/e2e/dist/cli/bin.js run --config e2e.browser-run.config.ts; setBROWSER_RUN_SCOPE=attemptfor the second run.browser.back()waiting forload, followed by video cleanup on the closed page. This limitation is documented. Rerunning with--grep-invert 'navigation verbs'passed every selected test:Maintainer verification on 2026-11-12 after rebasing onto main:
pnpm checkpassed, including the build, public type checks, and docs checks.pnpm --filter @e2e-dev/testbed testpassed 588 tests, 1 skipped;pnpm --filter @e2e-dev/web-benchmark testpassed 93 tests./browser-run/devtools/browserpath.