Repository navigation
fix(browser): preserve native CORS preflights - #185028
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR replaces catch-all Playwright routing with document-only CDP interception and preserves healthy response bodies during successful cleanup. Example: A guarded page sends a cross-origin PUT to a destination that rejects its CORS preflight.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR fixes a concrete CORS boundary defect still present on main; the latest revision resolves the previous unfinished-load finding, and no new actionable defect was found. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe browser plugin wraps Playwright navigation and actions with document policy checks; admitted documents reach Chromium while CORS and subresources retain native browser handling. flowchart TD
A[Browser operation] --> B[Navigation guard]
B --> C[Document CDP fence]
C --> D[Policy and live authority]
D --> E[Chromium document request]
A --> F[Native CORS and subresources]
E --> G[Commit and cleanup]
Technical reviewBest possible solution: Use the existing CDP fence as the single document-interception owner, preserve native CORS, and retire committed responses without canceling healthy loads. Do we have a high-confidence way to reproduce the issue? Current main contains the reported catch-all route mechanism, and the supplied real-Chromium differential shows it sends PUT to a destination that rejects native preflight; no target code was executed during this read-only review. Is this the best way to solve the issue? The change repairs the owning interception boundary, removes the replaced route path, and preserves the established policy and cleanup contracts without adding configuration or persistence. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 52e1c75ed3e3. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +64, Tests +464. Total +528 across 9 files. Added test files: 2. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (7 earlier review cycles)
Reviewed October 28, 2026, 5:38 PM ET / 21:38 UTC (Revision 8). |
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Merge recordSummary: Replaces catch-all Playwright routing with document-only CDP interception, restoring native CORS preflights while retaining navigation-policy enforcement. Successful cleanup preserves healthy main-frame and child response bodies. Decision Reason for Merge: Merged because Clawsweeper’s exact-head review found no actionable findings or before-merge blockers, supported by passing real-Chromium network and lifecycle regression tests. Compatibility Checks Done: Acceptance tests passed 75/75 and live Chromium tests passed 18/18. Production/test types, scoped lint, formatting, and compatibility review passed; no configuration, public API, dependency, or migration changes. Broad CI remains skipped while draft; newly triggered required checks will be checked after marking ready. |
* fix(browser): preserve native CORS preflights * fix(browser): preserve committed timeout recovery * fix(browser): settle committed action streams * fix(browser): recheck streaming commits during cleanup * test(browser): migrate navigation owner fixture * fix(browser): preserve committed document bodies after successful actions * test(browser): migrate dashboard navigation fixture to CDP
Summary
Browser navigation guards used Playwright catch-all page routing, which made Chromium treat intercepted CORS preflights as permissive and could send a cross-origin request the destination rejected. This change moves guard handling into document-only CDP interception, preserves native CORS, and explicitly cancels a committed timed-out page opening while retiring successful committed document ownership without canceling healthy response bodies or child loads. It preserves the invocation-scoped navigation policy introduced by #104254 and does not depend on the unmerged policy-removal proposal in #167703.
What Problem This Solves
In
extensions/browser/src/browser/pw-session-navigation.ts, guarded actions and guardedgotoused catch-all Playwright routing. Playwright could synthesize a successful CORS preflight, so a rejecting destination received the non-simplePUT.In
extensions/browser/src/browser/pw-session-navigation-fence.ts, the existing operation-owned fence tracked document redirects and out-of-process frames but did not own the route handler or limit Fetch interception to documents.The first document-only implementation waited for a terminal Network event after a committed streamed document timed out. Chromium does not consistently emit that event after
Page.stopLoading, so cleanup could replace the original PlaywrightTimeoutErrorand close a usable committed tab.A successful action could also return before delayed response headers committed streaming main-frame HTML. Cleanup sampled commitment once, then waited 20 seconds even after the later commit, failed, and retained interception until page close, so later navigation on the otherwise usable tab was aborted.
Successful action cleanup also used page-wide stopLoading after main-frame commit, truncating healthy delayed finite HTML and simultaneous child loads. Ownership now retires independently at each document commit; failure and cancellation still stop loading.
The net effect was excess page-script network authority before this fix plus committed-page recovery and successful-load regressions in its first revisions.
Why this design
Documentresources through the operation-owned CDP session; leave preflights and subresources on Chromium's native network path.Page.stopLoading, settle the fence's owned document state, and preserve the original navigation error.Why this does not conflict with related browser-navigation work
The shared navigation files compose with the existing policy: this branch narrows interception and repairs cleanup without redefining the allowed destinations.
Evidence
OPTIONSonly; with the base catch-allpage.route("**", route.fallback)mechanism, the same rejecting destination receivedPUTand noOPTIONS.node /tmp/openclaw-1129-probe/probe.mjsagainst pinnedplaywright-core1.64.1 reproduced the before/without-route differential shown below.OPTIONSand zeroPUTrequests.pnpm test:live -- extensions/browser/src/browser/pw-session-navigation-cors.live.test.ts— rejected action case passed.goto; destination rejects CORSOPTIONSand zeroPUTrequests.gotocase passed.OPTIONS, then exactly onePUT.127.0.0.2fixture destination recorded zero document requests under a policy allowing only127.0.0.1; source URL and title remained unchanged.pnpm test:live -- extensions/browser/src/browser/pw-session-navigation-authority.live.test.ts— allowed cases 6/6.createPageViaPlaywrightreturned the committed tab after the 1-second timeout; URL, titleCommitted stream, and bodyreadyremained usable.pnpm test:live -- extensions/browser/src/browser/pw-session-create-page-timeout.live.test.ts— 1/1 passed.pnpm exec vitest run --config test/vitest/vitest.extension-browser.config.ts ...andOPENCLAW_CHECK_CHANGED_SKIP_DEADCODE=1 node scripts/check-changed.mjs --base upstream/main.The sink observations come from fixture HTTP-server request counters and the real Chromium page's committed URL/title/body; fixtures use loopback only and contain no credentials or private endpoints. The redacted current-head terminal trace below comes directly from opt-in output after each sink assertion.
Original base-mechanism differential (real Chromium)
Here
guarded=trueinstalls the original base's exact catch-all Playwright route/fallback mechanism; the rejecting destination receivingPUTis the regression this PR removes.Real-Chromium terminal proof (current head)
Boundary decisions requested from browser owners
Page.stopLoadingremains the failure/cancellation boundary for retaining a usable committed tab.Testing
pw-session-navigation-cors.live.test.tsfor rejected/consenting CORS and denied-document source preservation.pw-session-create-page-timeout.live.test.tsthrough the shippedcreatePageViaPlaywrightentry point.pw-session-navigation-authority.live.test.tsfor allowed and revoked redirects across main-frame and OOPIF paths (12/12).pw-session.connections.test.tsfrom the removed route rendezvous to an EventEmitter-backed CDP session andFetch.enableinterception rendezvous; Clawsweeper's exact four-file acceptance command passed 75/75.upstream/main; the documented dead-code skip applies only to an unrelated full-tree finding.