Skip to main content

What is an iframe?

Iframes embed other pages within your current page. Sites use them for consent banners, payment widgets, chat bubbles, and third-party content. Elements inside iframes exist in a separate context than the main page.

Enable iframe support

Set iframes: true in your act(), observe(), and extract() commands.
// Act within iframes
await page.act({ action: "click the accept cookies button", iframes: true });

// Observe within iframes
const results = await page.observe({
  instruction: "Find the primary action button",
  iframes: true,
});

// Extract from iframes
const data = await page.extract({
  instruction: "Extract the product price from the payment widget",
  schema: z.object({
    price: z.string(),
  }),
  iframes: true,
});

Tips

  • Iframes can increase processing time. For best performance, use the iframe option only when necessary.
  • When you are unsure whether an element will be in an iframe, you can verify the presence of iframes in Stagehand logs.
  • If an element intermittently fails to be found, it may be inside a lazy‑loaded iframe. Add small waits between steps or re‑run your action.
You can enable experimental features (like Shadow DOM support) via your Stagehand configuration. See the configuration guide.

Next steps

Analyze pages with observe()

Use observe() to plan precise, single-step actions before executing them.

Extract data with extract()

Use extract() with a data schema to pull clean, typed data from any page.

Caching actions

Speed up repeated automations by caching actions.

Act fundamentals

Learn how to perform single-step actions reliably with act().