[feat]: add support for WebMCP tool invokation in iframes - #2878
Merged
Conversation
🦋 Changeset detectedLatest commit: 2a0744a The changes in this PR will be included in the next version bump. This PR includes changesets to release 19 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 6 files
Architecture diagram
sequenceDiagram
participant Client as Stagehand Client
participant Page as Extension Page Controller
participant Registry as Frame and Session Registry
participant Main as Main CDP Session
participant OOPIF as Adopted OOPIF CDP Session
participant Runtime as WebMCP Runtime in Page Frames
Note over Client,Runtime: WebMCP tools are discovered and invoked across the page's main target and adopted OOPIF targets
Client->>Page: tools()
Page->>Registry: Snapshot owned CDP sessions and frame ownership
Registry-->>Page: Main session and adopted OOPIF sessions
par Discover main-frame tools
Page->>Main: Subscribe to toolsAdded and toolsRemoved
Page->>Main: WebMCP.enable
Main->>Runtime: Enable WebMCP in main frame
Runtime-->>Main: toolsAdded / toolsRemoved events
Main-->>Page: Main-frame tool registrations
and Discover OOPIF tools
Page->>OOPIF: Subscribe to toolsAdded and toolsRemoved
Page->>OOPIF: WebMCP.enable
OOPIF->>Runtime: Enable WebMCP in iframe frame
Runtime-->>OOPIF: toolsAdded / toolsRemoved events
OOPIF-->>Page: OOPIF tool registrations
end
Page->>Page: Combine per-session snapshot and apply removals
Page->>Main: Remove temporary discovery listeners
Page->>OOPIF: Remove temporary discovery listeners
Page-->>Client: Tools with name, description, and owning frameId
Client->>Page: invokeWebMCPTool(frameId, toolName, input)
Page->>Registry: Resolve session owning frameId
Registry-->>Page: Main session or OOPIF session
alt Frame belongs to main target
Page->>Main: Subscribe to toolResponded
Page->>Main: WebMCP.invokeTool(frameId, toolName, input)
Main->>Runtime: Invoke tool in main frame
Runtime-->>Main: invocationId
Main-->>Page: invocationId
else Frame belongs to adopted OOPIF
Page->>OOPIF: Subscribe to toolResponded
Page->>OOPIF: WebMCP.invokeTool(frameId, toolName, input)
OOPIF->>Runtime: Invoke tool in iframe frame
Runtime-->>OOPIF: invocationId
OOPIF-->>Page: invocationId
else Frame is unknown or detached
Page-->>Client: Reject stale or unknown frame
end
Client->>Page: invocation.result() or waitForWebMCPInvocationResult(invocationId)
alt Response arrives on owning session
Runtime-->>Main: toolResponded(invocationId, status, output)
Main-->>Page: Correlated response
Page-->>Client: Structured tool result
else Response arrives on wrong session
Runtime-->>OOPIF: toolResponded with unrelated session
OOPIF-->>Page: Ignore due to session ownership mismatch
end
opt Cancel pending invocation
Client->>Page: cancelWebMCPInvocation(invocationId)
Page->>Registry: Resolve invocation's owning session
Registry-->>Page: Session recorded with invocation
Page->>OOPIF: WebMCP.cancelInvocation(invocationId)
OOPIF->>Runtime: Cancel iframe tool execution
OOPIF-->>Page: Cancellation response or completion event
end
alt OOPIF detaches
OOPIF-->>Page: Session detached
Page->>Registry: Remove OOPIF session and frame subtree
Page->>Page: Reject only invocations owned by detached session
Page->>OOPIF: Remove response listener and pending state
Page-->>Client: Detached-frame invocation errors
else Page is disposed
Client->>Page: dispose()
Page->>Main: Reject pending invocations and remove listeners
Page->>OOPIF: Reject pending invocations and remove listeners
end
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
miguelg719
approved these changes
Sep 2, 2026
seanmcguire12
force-pushed
the
add-webmcp-support-in-iframes
branch
from
September 3, 2026 11:23
f72cd16 to
2a0744a
Compare
This was referenced Sep 3, 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.
why
before this PR, WebMCP tools registered inside of iframes were unable to be discovered or invoked
what changed
test plan
Summary by cubic
WebMCP tools registered in out-of-process iframes (OOPIFs) are now discoverable and invokable; previously iframe tools were invisible and unusable. Invocation, response handling, and cancellation use the CDP session that owns the frame, while stale or detached frames fail instead of falling back to the main frame.
Written for commit 2a0744a. Summary will update on new commits.