Skip to content

fix(ego-browser): hit-test parent documents before clicking inside an iframe - #812

Open
wuwei-citro[bot] wants to merge 5 commits into
devfrom
wuwei/citro-5655
Open

wuwei-citro[bot] wants to merge 5 commits into
devfrom
wuwei/citro-5655

Conversation

@wuwei-citro

@wuwei-citro wuwei-citro Bot commented Nov 26, 2026

Copy link
Copy Markdown

Problem

page.click() checked for pointer interception only in the target's own frame. Native input is routed from the top document down. When an overlay in a parent document covered an iframe, the click landed on the overlay, but click() still returned a successful receipt {} and the target never received the event. A common case is an admin UI that shows a dialog with a full-screen shade in the top window over a form iframe. An overlay inside the same iframe was already reported correctly (CITRO-5655, GitHub #798).

Fix

  • Add assertFrameOwnersReceivePointerEvents in src/driver/page-actions.ts. It walks from the target's frame up to the top Page. At each step it resolves the owner <iframe> in the parent's session, translates the action point into that document (content-box offset, CSS scale) and runs the shared interceptingElementAtPoint there. If anything other than that iframe is hit, it throws the existing transient "<x> intercepts pointer events" ElementResolutionError, so the retry loop waits for the overlay to disappear, as it already does for same-frame overlays.
  • The walk works for same-process and out-of-process parents, using iframeSessions and its parentFrameIds.
  • page.click runs the check before the first pointer move. For a same-process iframe it runs it again after the hover move, so overlays created by hover in the parent are also caught. force: true skips the check.
  • The activation click that page.fill performs runs the same check.
  • If an ancestor's viewport does not contain the translated point, the walk stops without failing, so existing viewport handling does not change.
  • Move frame-owner resolution into a small resolveFrameOwner helper, shared with ensureFrameOwnerInView.

Verification

  • New unit tests in src/page-actions.test.mjs:
    • a parent-document overlay over a same-process iframe rejects with a transient error naming the overlay, and no pointer input is sent;
    • a nested OOPIF chain is hit-tested in each ancestor session, and the point is translated between steps;
    • force skips the check.
  • The real-browser E2E case Page click hit target now covers the reproduction from the issue: a srcdoc iframe whose target is covered by a parent overlay, and by an overlay inside the iframe. Both reject without reaching the target, and the target receives the click once it is uncovered.
  • npm --prefix package/ego-browser test: 674/674 pass.
  • npm --prefix package/ego-browser run e2e: Page click hit target passes (26 assertions). Some unrelated cases failed in local runs, and the set changed from run to run (page-ledger checks, evaluate-timeout recovery, fresh-process pending navigation). Page actionability passed in one run and exited early in the other.

🤖 Generated with Claude Code

… iframe

page.click only ran its pointer-interception check in the target's own
frame. Native input is routed from the top document down, so an overlay in
a parent document that covers the iframe (for example a layui dialog shade
in the top window over a form iframe) received the click while click()
returned a successful receipt and the target never saw the event.

Walk the iframe chain from the target's frame to the top Page, translate
the action point into each owner <iframe>'s document and require that the
element hit there is that iframe. A covered iframe now fails with the same
transient "<x> intercepts pointer events" error as an overlay inside the
iframe, so the retry loop waits for it to go away. The check covers
same-process and out-of-process parents, runs again after the hover move
for same-process iframes, is skipped with force, and also guards the
activation click page.fill performs.

Fixes CITRO-5655.

Co-Authored-By: Claude <noreply@anthropic.com>
@wuwei-citro

wuwei-citro Bot commented Nov 26, 2026

Copy link
Copy Markdown
Author

Verification on daa0a412

e2e — inconclusive

no report was written (exit 0)
{"ok":true,"assertions":10}

{"ok":true,"assertions":24}

{"ok":true,"assertions":31}

{"ok":true,"assertions":6}

{"ok":true,"assertions":18}

{"ok":true,"assertions":23}

{"ok":true,"assertions":1}

{"ok":true,"assertions":3}

{"ok":true,"assertions":13}

{"ok":true,"assertions":4}

{"ok":true,"assertions":38}

{"ok":true,"assertions":9}

{"ok":true,"assertions":7}

{"ok":true,"assertions":5}

{"cleanup":{"done":true}}
{"ok":true,"assertions":0}

These checks run on the bot's host and do not block the review loop; a human decides whether they matter.

@github-actions

Copy link
Copy Markdown

🤖 Codex Review · daa0a412

2026-11-26 03:13 UTC · generated automatically by openai/codex-action

  • [Minor] package/ego-browser/src/driver/page-actions.ts:1789 — The ancestor check can accept a hit on an interactive wrapper instead of the iframe.
    interceptingElementAtPoint deliberately accepts interactive ancestors. If an iframe has pointer-events: none inside a wrapper with role="button", this check passes even though native input reaches the wrapper and the framed target receives nothing. Require the hit element to be the iframe, retaining shadow-root handling, and add a regression test for this case.

…ents

An interactive wrapper around an iframe with pointer-events: none passed
interceptingElementAtPoint, yet the wrapper receives the native click.

Co-Authored-By: Claude <noreply@anthropic.com>
@wuwei-citro

wuwei-citro Bot commented Nov 26, 2026

Copy link
Copy Markdown
Author

Review round 1

  • [Minor] page-actions.ts: ancestor check accepted an interactive wrapper instead of the iframe. Fixed in 996678a. The parent-document check (frameOwnerReceivesPointer) no longer uses interceptingElementAtPoint. That helper treats an interactive ancestor as a valid hit, but only the <iframe> itself forwards input into its document. The check now calls hitElementAtPoint, which still descends through shadow roots, and requires the hit element to be the iframe. Any other element is reported as <...> intercepts pointer events; if nothing is hit, the owner document's root element is reported. Added the regression test Page click parent hit test requires the iframe itself, not an interactive wrapper in src/page-actions.test.mjs. It takes the real check source that clickInPage sends and runs it against a fake parent document. In that document the hit lands on a role="button" wrapper around the iframe, as it does when the iframe has pointer-events: none, and the check must reject it. The test also confirms that a hit on the iframe itself still passes and returns the translated point. npm --prefix package/ego-browser test passes (675/675). The real-browser E2E was not run here.

@wuwei-citro

wuwei-citro Bot commented Nov 26, 2026

Copy link
Copy Markdown
Author

Verification on 996678ac

e2e — inconclusive

no report was written (exit 0)
{"ok":true,"assertions":10}

{"ok":true,"assertions":24}

{"ok":true,"assertions":31}

{"ok":true,"assertions":6}

{"ok":true,"assertions":18}

{"ok":true,"assertions":23}

{"ok":true,"assertions":1}

{"ok":true,"assertions":3}

{"ok":true,"assertions":13}

{"ok":true,"assertions":4}

{"ok":true,"assertions":38}

{"ok":true,"assertions":9}

{"ok":true,"assertions":7}

{"ok":true,"assertions":5}

{"cleanup":{"done":true}}
{"ok":true,"assertions":0}

These checks run on the bot's host and do not block the review loop; a human decides whether they matter.

@github-actions

Copy link
Copy Markdown

🤖 Codex Review · 996678ac

2026-11-26 03:28 UTC · generated automatically by openai/codex-action

  • [Minor] package/ego-browser/src/driver/page-actions.ts:1779 — The coordinate conversion incorrectly rejects unobstructed targets inside rotated or skewed iframes.
    getBoundingClientRect() returns an axis-aligned bounding box, so its width and height ratios cannot represent rotation or skew. For example, a target near a corner of a square OOPIF rotated 45 degrees maps outside the iframe’s actual polygon, causing a false interception error. Use a transform-aware mapping and add coverage for a rotated iframe.

getBoundingClientRect is axis-aligned, so rotated or skewed iframes mapped
the framed point to the wrong place in the parent document and reported a
false interception. Map through the iframe's DOM.getContentQuads border-box
quad instead, falling back to the bounding box when no quad is available.

Co-Authored-By: Claude <noreply@anthropic.com>
@wuwei-citro

wuwei-citro Bot commented Nov 26, 2026

Copy link
Copy Markdown
Author

Review round 2

  • [Minor] page-actions.ts:1779: rotated or skewed iframes were wrongly rejected. Fixed in 47e3f9b. The parent-document hit test now asks for the owner <iframe>'s transformed border-box quad with DOM.getContentQuads in the owner session. It maps the framed point through that quad's affine corners (top-left, top-right, bottom-left), so rotation, skew and scale are handled. The quad's bounding box is lined up with the iframe's getBoundingClientRect(), so the result is in the owner document's viewport coordinates even if CDP reports the quad relative to an ancestor viewport. When no quad is available, the check falls back to the earlier bounding-box scaling. Added the test Page click parent hit test maps the point through a rotated iframe. It checks that the quad is passed to the check, then runs the real in-page function against a fake parent document with an iframe rotated 90°. The rotated mapping hits the iframe at (280, 210), and a quad offset by an ancestor viewport gives the same point. The old axis-aligned estimate (110, 220) is shown to produce the false interception. npm --prefix package/ego-browser test passes (676/676), and so do the pre-commit hooks, including prettier.

@wuwei-citro

wuwei-citro Bot commented Nov 26, 2026

Copy link
Copy Markdown
Author

Verification on 47e3f9b7

e2e — inconclusive

no report was written (exit 0)
{"ok":true,"assertions":10}

{"ok":true,"assertions":24}

{"ok":true,"assertions":31}

{"ok":true,"assertions":6}

{"ok":true,"assertions":18}

{"ok":true,"assertions":23}

{"ok":true,"assertions":1}

{"ok":true,"assertions":3}

{"ok":true,"assertions":13}

{"ok":true,"assertions":4}

{"ok":true,"assertions":38}

{"ok":true,"assertions":9}

{"ok":true,"assertions":7}

{"ok":true,"assertions":5}

{"cleanup":{"done":true}}
{"ok":true,"assertions":0}

These checks run on the bot's host and do not block the review loop; a human decides whether they matter.

@github-actions

Copy link
Copy Markdown

🤖 Codex Review · 47e3f9b7

2026-11-26 03:39 UTC · generated automatically by openai/codex-action

  • [Major] package/ego-browser/src/driver/page-actions.ts:334 — The ancestor hit test after pointer movement is skipped for OOPIF targets.
    If entering a cross-origin iframe creates a parent-document overlay, the initial check passes, but this second check only runs for same-process frames. The subsequent press can hit the overlay while page.click() reports success. Recheck ancestor interception after hovering OOPIF targets and add a regression test.

  • [Minor] package/ego-browser/src/driver/page-actions.ts:1799 — Bounding-box alignment cannot convert ancestor-rotated quads into the owner document’s coordinates.
    For nested frames, CDP quads can include an ancestor’s rotation while getBoundingClientRect() uses the iframe’s own document coordinates. Independently rescaling the axes preserves that unwanted rotation, so the check tests another point and can falsely reject valid clicks or miss overlays. Convert the quad through the ancestor transform, and cover a rotated ancestor containing an untransformed iframe.

…or rotation

Hovering a cross-origin iframe target can open a parent-document overlay
after the first ancestor hit test, so recheck the ancestors before the
press, as the same-process path already does.

An iframe's content quad can carry an ancestor frame's rotation. Map it
back into the owner document's viewport through the inverse affine
transform given by the owner's untransformed root element quad, keeping
the bounding-box alignment only as a fallback.

Co-Authored-By: Claude <noreply@anthropic.com>
@wuwei-citro

wuwei-citro Bot commented Nov 26, 2026

Copy link
Copy Markdown
Author

Review round 3

  • [Major] Ancestor hit test skipped after hovering OOPIF targets (page-actions.ts): fixed. After the hover mouseMoved, cross-process iframe targets now run assertFrameOwnersReceivePointerEvents again before the press, the same way the same-process path does, so an overlay that the hover opens in a parent document makes page.click() fail instead of reporting success. New test Page click rechecks parent documents after hovering an OOPIF target: the first ancestor check passes and the second reports an overlay. The test checks that the click is rejected and that only the mouseMoved was dispatched, with no press.
  • [Minor] Bounding-box alignment keeps an ancestor's rotation (page-actions.ts): fixed. The parent hit test now also gets the content quad of the owner document's root element, which is reported in the same coordinate space as the iframe's quad. When that root element has no transform, its known viewport rectangle and its quad define the affine map from the owner viewport into the reported space. The check inverts that map, which removes the ancestor's rotation, scale and offset, and it falls back to the old bounding-box alignment only when no usable root quad exists. New test Page click parent hit test undoes an ancestor rotation around an untransformed iframe: the owner document sits in a frame rotated 90°, and the test checks that the framed point maps back to (110, 220) rather than to the wrong point (280, 210) the bounding box gives. Two existing tests now expect the extra rootQuad argument.
  • npm --prefix package/ego-browser test passes (678/678), and so do the pre-commit hooks, including Prettier.

@wuwei-citro

wuwei-citro Bot commented Nov 26, 2026

Copy link
Copy Markdown
Author

Verification on 226029f6

e2e — inconclusive

no report was written (exit 0)
{"ok":true,"assertions":10}

{"ok":true,"assertions":24}

{"ok":true,"assertions":31}

{"ok":true,"assertions":6}

{"ok":true,"assertions":18}

{"ok":true,"assertions":23}

{"ok":true,"assertions":1}

{"ok":true,"assertions":3}

{"ok":true,"assertions":13}

{"ok":true,"assertions":4}

{"ok":true,"assertions":38}

{"ok":true,"assertions":9}

{"ok":true,"assertions":7}

{"ok":true,"assertions":5}

{"cleanup":{"done":true}}
{"ok":true,"assertions":0}

These checks run on the bot's host and do not block the review loop; a human decides whether they matter.

@github-actions

Copy link
Copy Markdown

🤖 Codex Review · 226029f6

2026-11-26 03:50 UTC · generated automatically by openai/codex-action

  • [Minor] package/ego-browser/src/driver/page-actions.ts:1804 — The quad interpolation hit-tests the wrong point for iframes rendered with CSS perspective.
    A perspective-transformed quad is not a parallelogram, so mapping through three corners with an affine formula produces incorrect coordinates. For an OOPIF, this can reject an unobstructed click or miss an overlay at the actual click location. Use a projective mapping for these quads and add a test with perspective(...) rotateY(...).

…me quads

Replace the three-corner affine interpolation with a projective
(square-to-quad homography) map, for both the iframe quad and the
ancestor root quad, so iframes styled with perspective() land on the
right point in the parent document.

Co-Authored-By: Claude <noreply@anthropic.com>
@wuwei-citro

wuwei-citro Bot commented Nov 26, 2026

Copy link
Copy Markdown
Author

Review round 4

  • [Minor] page-actions.ts:1804 – perspective quads mapped affinely: Fixed in b2b90df. frameOwnerReceivesPointer now maps the frame-local point onto the iframe's content quad with a projective (unit-square-to-quad homography) map instead of three-corner affine interpolation. The same homography is used for the ancestor root quad and inverted, so an ancestor frame with perspective is undone correctly too. Parallelogram quads (translation, rotation, skew) give the same results as before. A degenerate quad falls back to the existing axis-aligned path. Added the test Page click parent hit test maps the point through a perspective-transformed iframe. It builds the quad of a 200x200 iframe styled perspective(400px) rotateY(60deg), asserts that the affine estimate is more than 2px off, and checks that the real check hit-tests the projected point exactly, both with and without a root quad. npm --prefix package/ego-browser test passes (679/679), and so do the pre-commit hooks, including the Prettier style check.

@wuwei-citro

wuwei-citro Bot commented Nov 26, 2026

Copy link
Copy Markdown
Author

Verification on b2b90df8

e2e — inconclusive

no report was written (exit 0)
{"ok":true,"assertions":10}

{"ok":true,"assertions":24}

{"ok":true,"assertions":31}

{"ok":true,"assertions":6}

{"ok":true,"assertions":18}

{"ok":true,"assertions":23}

{"ok":true,"assertions":1}

{"ok":true,"assertions":3}

{"ok":true,"assertions":13}

{"ok":true,"assertions":4}

{"ok":true,"assertions":38}

{"ok":true,"assertions":9}

{"ok":true,"assertions":7}

{"ok":true,"assertions":5}

{"cleanup":{"done":true}}
{"ok":true,"assertions":0}

These checks run on the bot's host and do not block the review loop; a human decides whether they matter.

@github-actions

Copy link
Copy Markdown

🤖 Codex Review · b2b90df8

2026-11-26 04:09 UTC · generated automatically by openai/codex-action

No issues found that require changes.

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.

0 participants