Skip to content

feat: support cross-origin iframe snapshots and interactions via Target.setAutoAttach#949

Merged
ctate merged 4 commits intovercel-labs:mainfrom
hyunjinee:feat/cross-origin-iframe-snapshot
Mar 20, 2026
Merged

feat: support cross-origin iframe snapshots and interactions via Target.setAutoAttach#949
ctate merged 4 commits intovercel-labs:mainfrom
hyunjinee:feat/cross-origin-iframe-snapshot

Conversation

@jin-2-kakaoent
Copy link
Contributor

@jin-2-kakaoent jin-2-kakaoent commented Mar 20, 2026

Summary

Fixes #925.

agent-browser cannot interact with cross-origin iframes — snapshot fails with CDP error (Accessibility.getFullAXTree): Frame with the given frameId is not found. This is because cross-origin iframes exist behind a security boundary that prevents the parent page's CDP session from accessing them via frameId.

This PR enables Target.setAutoAttach with flatten: true on page sessions so Chrome auto-creates dedicated CDP sessions for cross-origin iframe targets. These sessions are tracked and used for accessibility tree queries, element resolution, and interactions, bypassing the security boundary.

Reproduction

<!-- /tmp/cross-origin-test.html -->
<html>
<body>
  <h1>Parent Page</h1>
  <iframe src="https://example.com" width="800" height="400" title="Cross-origin example"></iframe>
</body>
</html>

Snapshot

Before (main):

$ agent-browser open file:///tmp/cross-origin-test.html

$ agent-browser snapshot -i -c
- Iframe "Cross-origin example" [ref=e2]
# ↑ No iframe content shown

$ agent-browser frame @e2
✓ Done

$ agent-browser snapshot -i -c
✗ CDP error (Accessibility.getFullAXTree): Frame with the given frameId is not found.

After (this PR):

$ agent-browser open file:///tmp/cross-origin-test.html

$ agent-browser snapshot -i -c
- Iframe "Cross-origin example" [ref=e2]
  - link "Learn more" [ref=e4]
# ↑ Cross-origin iframe content now visible

$ agent-browser frame @e2
✓ Done

$ agent-browser snapshot -i -c
- link "Learn more" [ref=e2]
# ↑ No more error

Interaction (click, hover)

Before (main): Cannot access elements inside cross-origin iframes — only the iframe element itself is visible as [ref=e2].

After (this PR):

$ agent-browser frame @e2
✓ Done

$ agent-browser click @e2    # clicks "Learn more" link inside iframe
✓ Done

$ agent-browser hover @e2
✓ Done

Test plan

  • Cross-origin iframe content appears in snapshot -i -c output
  • frame @ref + snapshot works for cross-origin iframes (previously: Frame with the given frameId is not found)
  • frame main + snapshot returns to parent page
  • click on cross-origin iframe element works
  • hover on cross-origin iframe element works
  • Same-origin iframe snapshot still works (regression)
  • Plain page snapshot still works (regression)
  • Navigation clears stale iframe sessions
  • Tab switch clears iframe sessions
  • Screenshot command still works (regression)
  • Unit tests for resolve_ax_session and resolve_frame_session
  • cargo test, cargo fmt, cargo clippy all pass
  • Direct comparison between main and feature branch binaries

@vercel
Copy link
Contributor

vercel bot commented Mar 20, 2026

@hyunjinee is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

@jin-2-kakaoent jin-2-kakaoent force-pushed the feat/cross-origin-iframe-snapshot branch 3 times, most recently from 9a74ccb to 8a6d04c Compare March 20, 2026 16:02
@jin-2-kakaoent jin-2-kakaoent changed the title feat: support cross-origin iframe snapshots via Target.setAutoAttach feat: support cross-origin iframe snapshots and interactions via Target.setAutoAttach Mar 20, 2026
…et.setAutoAttach (vercel-labs#925)

Enable Target.setAutoAttach with flatten: true on page sessions so Chrome
auto-creates dedicated CDP sessions for cross-origin iframe targets.

- Add DrainedEvents struct, iframe_sessions map, attach/detach event handling
- Extract resolve_ax_session (shared) and resolve_frame_session helpers
- resolve_element_object_id returns (object_id, effective_session) tuple
- resolve_element_center returns (x, y, effective_session) tuple
- Input dispatch (click/hover/tap) uses effective session for correct coordinates
- Thread iframe_sessions through element.rs, interaction.rs, screenshot.rs
- Clear iframe sessions on navigate, tab switch, tab new, tab close
- Ignore Target.setAutoAttach failure for non-Chrome backends (Lightpanda)
- Unit tests for session resolution logic
@jin-2-kakaoent jin-2-kakaoent force-pushed the feat/cross-origin-iframe-snapshot branch from 8da4487 to 0d91ef7 Compare March 20, 2026 16:19
@jin-2-kakaoent jin-2-kakaoent force-pushed the feat/cross-origin-iframe-snapshot branch from bd65a1c to cca30a3 Compare March 20, 2026 16:36
@ctate ctate merged commit 59b6e5a into vercel-labs:main Mar 20, 2026
9 of 11 checks passed
@ctate
Copy link
Collaborator

ctate commented Mar 20, 2026

So good. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cross-origin iframe support: use Target.setAutoAttach for separate sessions

3 participants