Keep tabs alive when WebMCP discovery runs on scratch-document pages - #431
Merged
Merged
Conversation
The polyfill bridge read document.modelContext in every frame on every tool listing. On a frame that had already read modelContext on another document, that read was a second WebMCP host bind and Chromium killed the renderer. Read it only when the page has a navigator.modelContext polyfill to bridge, and add an e2e test that lists tools on such pages and asserts the renderer survives.
rgarcia
force-pushed
the
hypeship/webmcp-scratch-document-bind
branch
from
October 1, 2026 18:59
fc5a970 to
f8de255
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit f8de255. Configure here.
sjmiller609
approved these changes
Oct 1, 2026
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
GET /webmcp/toolscan kill the tab (Terminating renderer for bad IPC message, reason 346) on pages that have already readmodelContexton a second document in the same frame. Some sandboxing libraries do this at startup when they copy the properties of adocument.implementation.createHTMLDocument()document.The polyfill bridge read
window.document.modelContextin every web frame on every listing, before it checked whether the page had a polyfill. On those pages that read was the second bind, and Chromium killed the renderer. The listing still returned200 {"tools":[]}.Background
bad_message.cc). That's the "Aw, Snap".RenderFrameHost. A document is the DOM loaded in a frame. JS can create extra detached documents withdocument.implementation.createHTMLDocument(), and those still count against the frame whose script created them.document.modelContextis the registry where a page registers tools for agents. The tools have to be visible outside the page, for example through the CDPWebMCPdomain, so the registry lives in the browser process. Its browser-side half (ModelContextHost) is stored once per frame.ModelContextthe first time JS reads.modelContexton that document, and creating it sends a bind request to the browser. Later reads of the same document return the same object, so they don't bind again.The conflict: Blink binds once per document, but the browser accepts one bind per frame. When two documents in one frame read
modelContext, the browser kills the renderer.The exact bind rule hasn't been checked in Chromium source. The behavior is confirmed by repro:
modelContextrepeatedly is fine, including from an extension's isolated world.navigator.modelContextnever binds.document.modelContextonly exists here because the image launches Chromium with--enable-features=WebMCPTesting,DevToolsWebMCPSupport(server/cmd/wrapper/chromium.go).sequenceDiagram participant Page as sandbox iframe JS (renderer) participant Bridge as polyfill_bridge.js (renderer) participant Host as browser process: frame's ModelContextHost Page->>Page: createHTMLDocument().modelContext Page->>Host: bind #1 (scratch document) Host-->>Page: ok Note over Bridge: client calls GET /webmcp/tools Bridge->>Bridge: sync() → nativeContext() → window.document.modelContext Bridge->>Host: bind #2 (frame's real document) Host-->>Page: duplicate bind → renderer killed (reason 346)syncPolyfillTools(server/lib/webmcpclient/polyfill.go) runs the bridge in every web frame, including sandbox iframes. Before this change,sync()callednativeContext()first, and that function readswindow.document.modelContext.Changes
polyfill_bridge.js):sync()checksnavigator.modelContextfor a polyfill first, and readsdocument.modelContextonly when one exists.polyfill()no longer compares against the native context, sinceisNativealready excludes the native registry.TestPlaywrightExecuteAPI/WebMCPScratchDocument): loads a page that readsmodelContexton a scratch document, once at top level and once in asrcdocframe. It lists tools once, then asserts that no new reason-346 kill appears in the Chromium log and that the page kept its JS state. It runs as the last subtest on the shared container, because a killed foreground tab also stalls/playwright/execute.Not covered
navigator.modelContextpolyfill in the same frame as a scratch-document read can still be killed: the bridge has to readdocument.modelContextthere to register the polyfill's tools.document.modelContexton these pages triggers the same kill. That includes the page itself and extension content scripts (reproduced with an unpacked extension). This PR only stops the bridge from being that reader. A full fix needs Chromium to accept one bind per document, or the image to stop exposingdocument.modelContextto every page by default.Testing
Ran locally against
onkernel/chromium-headless:e77bac1:WebMCPScratchDocumentcases fail with reason 346 after a200listing.TestPlaywrightExecuteAPIsubtests pass, including the existingWebMCPPolyfill.go test ./lib/webmcpclient/passes.CI is green on this branch. Only the headless image was tested locally.