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): keep out-of-process iframes out of the v1 frame retry

Zhuowei Wang18f499882c0f
diff --git a/package/ego-browser/src/driver/element-ops.ts b/package/ego-browser/src/driver/element-ops.ts
index c52c018..c204e5f 100644
--- a/package/ego-browser/src/driver/element-ops.ts
+++ b/package/ego-browser/src/driver/element-ops.ts
@@ -34,19 +34,36 @@ export async function resolveInPageFrames<T>(
}
}
+/**
+ * Frames rendered by the Page's own process. An out-of-process iframe is
+ * listed in the frame tree too, but only its own session can address it, so
+ * it and every frame below it are left out. Without the target list there is
+ * no way to tell them apart, and the caller keeps the top-document miss.
+ */
async function sameProcessFrames(): Promise<Map<string, string | undefined>> {
const frames = new Map<string, string | undefined>();
let tree;
+ let targetInfos;
try {
- tree = (await cdp("Page.getFrameTree"))?.frameTree;
+ [tree, targetInfos] = await Promise.all([
+ cdp("Page.getFrameTree").then((result) => result?.frameTree),
+ cdp("Target.getTargets").then((result) => result?.targetInfos),
+ ]);
} catch {
return frames;
}
+ if (!Array.isArray(targetInfos)) return frames;
+ // An out-of-process iframe target's id is its frame id.
+ const outOfProcess = new Set(
+ targetInfos
+ .filter((info) => info?.type === "iframe")
+ .map((info) => info.targetId),
+ );
const visit = (node) => {
for (const child of node?.childFrames || []) {
- if (typeof child?.frame?.id === "string") {
- frames.set(child.frame.id, undefined);
- }
+ const frameId = child?.frame?.id;
+ if (typeof frameId !== "string" || outOfProcess.has(frameId)) continue;
+ frames.set(frameId, undefined);
visit(child);
}
};
diff --git a/package/ego-browser/src/driver/observe.test.mjs b/package/ego-browser/src/driver/observe.test.mjs
index 0ad1225..a1bd5e6 100644
--- a/package/ego-browser/src/driver/observe.test.mjs
+++ b/package/ego-browser/src/driver/observe.test.mjs
@@ -330,6 +330,7 @@ test("elementCenter finds a role locator in a same-process iframe after a top-do
},
};
}
+ if (method === "Target.getTargets") return { targetInfos: [] };
if (method === "DOM.getBoxModel") {
assert.equal(params.backendNodeId, 7);
return { model: { content: [10, 20, 50, 20, 50, 40, 10, 40] } };
@@ -359,6 +360,7 @@ test("elementCenter keeps a top-document miss when the Page has no iframes", asy
if (method === "Page.getFrameTree") {
return { frameTree: { frame: { id: "main-frame" } } };
}
+ if (method === "Target.getTargets") return { targetInfos: [] };
return {};
},
});
@@ -371,3 +373,44 @@ test("elementCenter keeps a top-document miss when the Page has no iframes", asy
restore();
}
});
+
+test("elementCenter does not search an out-of-process iframe through the Page session", async () => {
+ const axFrameIds = [];
+ const restore = setOverrides({
+ cdpOverride(method, params) {
+ if (method === "Accessibility.getFullAXTree") {
+ axFrameIds.push(params.frameId ?? null);
+ return { nodes: [] };
+ }
+ if (method === "Page.getFrameTree") {
+ return {
+ frameTree: {
+ frame: { id: "main-frame" },
+ childFrames: [
+ {
+ frame: { id: "oopif-frame" },
+ childFrames: [{ frame: { id: "oopif-child" } }],
+ },
+ { frame: { id: "same-process-frame" } },
+ ],
+ },
+ };
+ }
+ if (method === "Target.getTargets") {
+ return {
+ targetInfos: [{ type: "iframe", targetId: "oopif-frame" }],
+ };
+ }
+ return {};
+ },
+ });
+ try {
+ await assert.rejects(
+ () => elementCenter("loc=role:button[name='Missing']"),
+ /matched 0 elements/,
+ );
+ } finally {
+ restore();
+ }
+ assert.deepEqual(axFrameIds, [null, null, "same-process-frame"]);
+});