Repository navigation
Description
Environment Information
Stagehand:
- Language/SDK: TypeScript (Node.js 20)
- Stagehand version: 3.6.0
Issue Description
[ERROR] [stagehand:action] error performing click {"error":{"value":"main world not ready for frame 70CB7189B07A8177D60AB6463B624950"},"xpath":{"value":"xpath=/html[1]/body[1]/form[1]/div[3]/section[2]/div[1]/div[1]/div[1]/div[2]/div[1]/iframe[1]"}}
StagehandClickError: Error Clicking Element with selector: main world not ready for frame 70CB7189B07A8177D60AB6463B624950 Reason: xpath=...iframe[1]
at clickElement (dist/esm/lib/v3/handlers/handlerUtils/actHandlerUtils.js:268:15)
at async performUnderstudyMethod (dist/esm/lib/v3/handlers/handlerUtils/actHandlerUtils.js:18:9)
at async ActHandler.takeDeterministicAction (dist/esm/lib/v3/handlers/actHandler.js:227:21)
When act() targets an element that is (or is inside) a cross-origin iframe — e.g. a Vimeo/YouTube embed — and that iframe's document hasn't finished loading yet, the click always fails after ~1 second with main world not ready for frame <id>.
Cross-origin embeds (video players, payment widgets, etc.) often take a few seconds to load, so agent that interact with them fail intermittently The same click succeeds instantly (~35ms) when retried after the iframe finishes loading.
Steps to Reproduce
Real-world case: navigate to https://adequancanine.com/committed-to-dogs (Vimeo embeds) and run act("click the video iframe") while the player is still loading.
Deterministic repro without an LLM — the iframe's document is delayed to make the timing reliable:
import { Stagehand } from "@browserbasehq/stagehand";
import puppeteer from "puppeteer"; // only used to delay the iframe request
const XPATH = "xpath=/html[1]/body[1]/form[1]/div[3]/section[2]/div[1]/div[1]/div[1]/div[2]/div[1]/iframe[1]";
const stagehand = new Stagehand({ env: "LOCAL", verbose: 0 });
await stagehand.init();
const page = stagehand.context.activePage();
// Delay the iframe's document by 8s so the click reliably runs while it is still loading
const browser = await puppeteer.connect({ browserWSEndpoint: stagehand.connectURL(), defaultViewport: null });
const ppage = (await browser.pages())[0];
await ppage.setRequestInterception(true);
ppage.on("request", (req) => {
if (req.url().includes("player.vimeo.com")) setTimeout(() => req.continue().catch(() => {}), 8000);
else req.continue().catch(() => {});
});
await page.goto("https://adequancanine.com/committed-to-dogs", { waitUntil: "domcontentloaded" });
// wait until the iframe ELEMENT exists in the parent DOM (its document is still loading)
while ((await page.mainFrame().locator(XPATH).count()) === 0) await new Promise((r) => setTimeout(r, 300));
await page.deepLocator(XPATH).click();
// => throws: "main world not ready for frame <id>" after ~1s
// retrying the same click after the iframe loads succeeds in ~35ms
Activity
harshmathurx commentedon Jul 15, 2026
@filip-michalsky took a look at this repro and it feels like a real readiness bug rather than a flaky click heuristic. The interesting part is that the target element exists in the parent DOM, but the cross-origin frame main world is not ready yet, so the deterministic action path is racing frame readiness instead of gating on it. My bias would be to treat this like a frame-lifecycle wait problem: when the target resolves to an iframe or an element inside one, wait for the destination frame readiness signal before attempting the click, instead of failing fast with the raw Playwright frame error. If that matches intended behavior, I’d be happy to put up a focused fix with a delayed-frame regression test.
harshmathurx commentedon Jul 21, 2026
cc @shrey150 since you’ve been landing the recent act/browse reliability work here — could you confirm whether this should be treated as a frame-readiness wait in the deterministic action path?
If yes, please assign this to me and I’ll put up a focused PR with a delayed cross-origin iframe regression. I’d keep the scope narrow: target resolves to an iframe / frame-owned element, wait for the frame execution context to be ready, then click; don’t change the broader click heuristic.
ritikpal1122 commentedon Aug 13, 2026
Checked this against v4.0.0 (
main@ 444dc3b) — still reproduces, just with a different error string.v3 threw
main world not ready for frame <id>after ~1s. v4 throwsStagehand extension world not ready for frame <id>; checked contexts: noneafter ~3.1s. Same trigger, and the same "succeeds instantly once the iframe finishes loading".Deterministic repro, no LLM: two distinct sites mapped to local servers so site-isolation makes a real OOPIF, and the child document response is delayed 12s while the
<iframe>element is in the parent DOM immediately. Identical across runs:Two things that sharpen the original report:
<iframe>fine while the child is loading; the deep XPath fails. Deep XPaths withiframe[n]steps are whatact()emits, which is why it's reachable fromact()but invisible to a CSS selector.Path through the code:
deepLocator.tsresolveLocatorTargettreats the trailingiframe[1]as a frame hop, so the target frame becomes the still-loading child even when the element being clicked is the iframe →frame.ts:186evaluateInLocatorWorld→waitForLocatorWorld(…, 1000)→executionContextRegistry.ts:112finds no candidate contexts because the document hasn't committed →isFallbackEligiblereturns false forhttp:→ the error rethrows.Nothing on that path waits on frame lifecycle, unlike
ensureChildFrameReady(frameLocator.ts:193), which gates onPage.lifecycleEventand treats a timeout as best-effort. The timeouts are hardcoded andLocatorClickOptionsonly exposesbutton/clickCount, so there's no user-side knob — retrying in userland is the only workaround today.So @harshmathurx's framing looks right, with one amendment: the wait needs to trigger when the selector resolves through a frame, not only when the target is inside one.
Repro script
fix: wait for the locator world when a deep XPath crosses an iframe (#…
fix: wait for the locator world when a deep XPath crosses an iframe (#…
fix: wait for the locator world when a deep XPath crosses an iframe (#…
[fix]: wait for the locator world when a deep XPath crosses an iframe (…