Skip to content

The fastest browser for AI agents to run browser automation, built for sharing your logged-in browser state with your AI agents, like Codex or Claude Code, without disturbing you. Zero cost, zero config.

fix(ego-browser): translate v1 click points out of same-process iframes

Joway@MacMini34855da02025
diff --git a/package/ego-browser/scripts/real-browser-e2e/cases/pointer.mjs b/package/ego-browser/scripts/real-browser-e2e/cases/pointer.mjs
index 743b5d7..6cd88fa 100644
--- a/package/ego-browser/scripts/real-browser-e2e/cases/pointer.mjs
+++ b/package/ego-browser/scripts/real-browser-e2e/cases/pointer.mjs
@@ -274,5 +274,12 @@ export function pointerCase() {
"partial,far,far",
"a rejected click dispatches nothing"
);
+ await js("window.scrollTo({ top: 0, behavior: 'instant' }); return true;");
+ await click("loc=role:button[name='Framed']");
+ await waitForJsValue(
+ "window.__clicked.join()",
+ "partial,far,far,framed",
+ "click scrolls a same-process iframe target into view and lands on it"
+ );
`;
}
diff --git a/package/ego-browser/scripts/real-browser-e2e/fixture.mjs b/package/ego-browser/scripts/real-browser-e2e/fixture.mjs
index 3a8c857..9509160 100644
--- a/package/ego-browser/scripts/real-browser-e2e/fixture.mjs
+++ b/package/ego-browser/scripts/real-browser-e2e/fixture.mjs
@@ -414,6 +414,11 @@ export async function startFixtureServer(taskName) {
<div id="gap"></div>
<button id="far">Far</button>
<button id="unreachable">Unreachable</button>
+ <iframe
+ title="framed"
+ style="display: block; height: 120px; border: 2px solid"
+ srcdoc="<button onclick='parent.__clicked.push(&quot;framed&quot;)'>Framed</button>"
+ ></iframe>
<script>
window.__clicked = [];
for (const button of document.querySelectorAll("button")) {
diff --git a/package/ego-browser/src/driver/action-target.ts b/package/ego-browser/src/driver/action-target.ts
index 04da26f..99bcb9e 100644
--- a/package/ego-browser/src/driver/action-target.ts
+++ b/package/ego-browser/src/driver/action-target.ts
@@ -250,28 +250,44 @@ export const SCROLL_TARGET_HELPERS = `
* if it cannot get there (fixed position, end of the scroll range), a click
* without a caller-chosen offset settles for its visible part. A point that is
* still outside is reported, because input dispatched there hits nothing.
+ *
+ * Input goes to the session's top viewport, so a point in a same-process iframe
+ * is translated out of it and has to be visible in both. `frameElement` is null
+ * across an origin boundary, where a separate session owns the frame's input.
*/
export const CLICK_POINT_HELPERS = `
${SCROLL_TARGET_HELPERS}
function clickPointForElement(element, offset) {
const view = element.ownerDocument.defaultView;
- const inViewport = (point) =>
+ const inViewport = (point, owner) =>
point.x >= 0 && point.y >= 0 &&
- point.x < view.innerWidth && point.y < view.innerHeight;
+ point.x < owner.innerWidth && point.y < owner.innerHeight;
+ const inputPoint = (point) => {
+ if (!point || !inViewport(point, view)) return null;
+ let { x, y } = point;
+ let current = view;
+ while (current.frameElement) {
+ const owner = current.frameElement;
+ const rect = owner.getBoundingClientRect();
+ x += rect.left + owner.clientLeft;
+ y += rect.top + owner.clientTop;
+ current = current.parent;
+ }
+ return inViewport({ x, y }, current) ? { x, y } : null;
+ };
const elementPoint = () => {
const rect = element.getBoundingClientRect();
return offset
? { x: rect.x + offset.x, y: rect.y + offset.y }
: { x: rect.x + rect.width / 2, y: rect.y + rect.height / 2 };
};
- let point = elementPoint();
- if (inViewport(point)) return point;
+ const unscrolled = inputPoint(elementPoint());
+ if (unscrolled) return unscrolled;
element.scrollIntoView({ block: "center", inline: "center", behavior: "instant" });
- point = elementPoint();
- if (inViewport(point)) return point;
- const visible = offset ? null : actionPointForElement(element);
- if (visible && inViewport(visible)) return visible;
- return { error: "element is not visible in the viewport" };
+ const point =
+ inputPoint(elementPoint()) ||
+ (offset ? null : inputPoint(actionPointForElement(element)));
+ return point || { error: "element is not visible in the viewport" };
}
`;
diff --git a/package/ego-browser/src/driver/pointer.test.mjs b/package/ego-browser/src/driver/pointer.test.mjs
index b449ea1..6934e75 100644
--- a/package/ego-browser/src/driver/pointer.test.mjs
+++ b/package/ego-browser/src/driver/pointer.test.mjs
@@ -2,6 +2,7 @@ import test from "node:test";
import assert from "node:assert/strict";
import { setOverrides } from "../../dist/src/state.js";
+import { CLICK_POINT_HELPERS } from "../../dist/src/driver/action-target.js";
import { click, scroll } from "../../dist/src/driver/pointer.js";
test("click resolves selector offsets without the public elementEval helper", async () => {
@@ -361,6 +362,76 @@ test("click scrolls a selector-relative point back into the viewport", async ()
assert.deepEqual(dispatchedPoints(calls)[0], [354, 286]);
});
+/**
+ * Run the real page-side click point against an element in a same-process
+ * iframe. Input is dispatched in the top viewport, so that is the coordinate
+ * space the result has to be in.
+ */
+function framedClickPoint({ rect, frame, offset = null, afterScroll = rect }) {
+ const top = { innerWidth: 800, innerHeight: 600, frameElement: null };
+ const view = {
+ innerWidth: 300,
+ innerHeight: 200,
+ frameElement: {
+ clientLeft: 2,
+ clientTop: 3,
+ getBoundingClientRect: () => frame,
+ },
+ parent: top,
+ };
+ let current = rect;
+ const domRect = () => ({
+ ...current,
+ x: current.left,
+ y: current.top,
+ right: current.left + current.width,
+ bottom: current.top + current.height,
+ });
+ const element = {
+ ownerDocument: { defaultView: view },
+ getBoundingClientRect: domRect,
+ getClientRects: () => [domRect()],
+ scrollIntoView() {
+ current = afterScroll;
+ },
+ };
+ return new Function(
+ "element",
+ "offset",
+ `${CLICK_POINT_HELPERS}; return clickPointForElement(element, offset);`,
+ )(element, offset);
+}
+
+test("click translates a scrolled same-process iframe point to the top viewport", () => {
+ assert.deepEqual(
+ framedClickPoint({
+ frame: { left: 50, top: 100 },
+ rect: { left: 10, top: 500, width: 100, height: 40 },
+ afterScroll: { left: 10, top: 20, width: 100, height: 40 },
+ }),
+ { x: 112, y: 143 },
+ );
+ assert.deepEqual(
+ framedClickPoint({
+ frame: { left: 50, top: 100 },
+ rect: { left: 10, top: 500, width: 100, height: 40 },
+ afterScroll: { left: 10, top: 20, width: 100, height: 40 },
+ offset: { x: 4, y: 6 },
+ }),
+ { x: 66, y: 129 },
+ );
+});
+
+test("click reports an iframe point that stays outside the top viewport", () => {
+ assert.deepEqual(
+ framedClickPoint({
+ frame: { left: 50, top: 900 },
+ rect: { left: 10, top: 20, width: 100, height: 40 },
+ }),
+ { error: "element is not visible in the viewport" },
+ );
+});
+
test("click does not second-guess explicit coordinates", async () => {
const { calls, restore, scrolls } = fakePage({ rect: CENTER_BELOW_FOLD });
try {