feat(browser): add cross-origin iframe support via CDP execution contexts#1084
Merged
jackwener merged 3 commits intojackwener:mainfrom Apr 19, 2026
Merged
Conversation
…exts Enable interaction with cross-origin iframes through CDP's execution context mechanism, without requiring content scripts or all_frames. - Track frame execution contexts via Runtime.executionContextCreated events - Add 'frames' action to list all child frames (including cross-origin) - Support frameIndex in 'exec' action to evaluate JS in specific frames - Add Page.frames() and Page.evaluateInFrame() APIs for CLI consumers - Tag cross-origin iframes with [F0]/[F1] indices in DOM snapshots - Add Page.getFrameTree to CDP allowlist Closes jackwener#1077 Change-Id: Id03361ddb616912dff3bfa8e59e8b68716de590b
5846bc8 to
19b56c9
Compare
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 cross-origin iframe support using CDP execution contexts, enabling AI agents to discover and interact with elements inside cross-origin iframes without content scripts.
Closes #1077
Problem
Currently,
opencli browser statedetects iframes but marks cross-origin ones as(cross-origin)with no way to interact. This is because:el.contentDocumentreturnsnullfor cross-origin iframes (browser security)Runtime.evaluateviachrome.debugger.sendCommand({ tabId })only runs in the main frameframeIndexfield exists to target a specific frameChanges
6 files, +153/-4 lines — focused and backward-compatible.
Extension layer
extension/src/protocol.ts'frames'toActionunion typeframeIndex?: numbertoCommandinterfaceextension/src/cdp.tsRuntime.executionContextCreated/Destroyed/ClearedeventsregisterFrameTracking()for event listener setupgetFrameTree(tabId)— wraps CDPPage.getFrameTreeevaluateInFrame(tabId, expression, frameId)— evaluate JS in a specific frame's contextextension/src/background.tsregisterFrameTracking()during initializationPage.getFrameTreetoCDP_ALLOWLISThandleFrames()— returns flat list of child frames with index/frameId/url/namehandleExec()— whenframeIndexis set, resolve it to a frameId and useevaluateInFrame()'frames'case to command switchCLI layer
src/browser/daemon-client.ts'frames'toDaemonCommand.actionunionframeIndex?: numbertoDaemonCommandsrc/browser/page.tsframes()method — list all child framesevaluateInFrame(js, frameIndex)— evaluate JS in a specific framesrc/browser/dom-snapshot.ts[F0],[F1]indices in snapshot outputuse: opencli browser framesDesign Decisions
CDP execution contexts over content scripts: Stays consistent with the existing pure-CDP architecture. No manifest changes needed, no
all_framesinjection.Frame index (not frameId): Users and AI agents work with simple 0-based indices from
opencli browser framesoutput, not opaque CDP frame IDs.Per-command frameIndex (not stored state): Follows the same pattern as
windowFocusedandidleTimeout— stateless, per-command relay.Backward compatible:
frameIndexis optional everywhere. When absent, all behavior is identical to before.Usage
Testing
frameIndex