Skip to content

Commit b769206

Browse files
fix: missing content from (some) same process iframes (#946)
1 parent 0c7c39b commit b769206

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

.changeset/sharp-meals-clap.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@browserbasehq/stagehand": patch
3+
---
4+
5+
fix: unable to act on/get content from some same process iframes

lib/a11y/utils.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
EncodedId,
1212
RichNode,
1313
ID_PATTERN,
14+
CdpFrame,
1415
} from "../../types/context";
1516
import { StagehandPage } from "../StagehandPage";
1617
import { LogLine } from "../../types/log";
@@ -442,12 +443,15 @@ export async function getCDPFrameId(
442443
const rootResp = (await sp.sendCDP("Page.getFrameTree")) as unknown;
443444
const { frameTree: root } = rootResp as { frameTree: CdpFrameTree };
444445

445-
const url = frame.url();
446+
const targetUrl: string = frame.url();
446447
let depth = 0;
447448
for (let p = frame.parentFrame(); p; p = p.parentFrame()) depth++;
448449

450+
const withFragment = (f: CdpFrame): string => f.url + (f.urlFragment ?? "");
451+
449452
const findByUrlDepth = (node: CdpFrameTree, lvl = 0): string | undefined => {
450-
if (lvl === depth && node.frame.url === url) return node.frame.id;
453+
if (lvl === depth && withFragment(node.frame) === targetUrl)
454+
return node.frame.id;
451455
for (const child of node.childFrames ?? []) {
452456
const id = findByUrlDepth(child, lvl + 1);
453457
if (id) return id;
@@ -467,7 +471,7 @@ export async function getCDPFrameId(
467471

468472
return frameTree.frame.id; // root of OOPIF
469473
} catch (err) {
470-
throw new StagehandIframeError(url, String(err));
474+
throw new StagehandIframeError(targetUrl, String(err));
471475
}
472476
}
473477

0 commit comments

Comments
 (0)