October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

How to Get an Iframe Element from a Puppeteer Frame

Use await frame.frameElement() to retrieve the DOM element hosting a Puppeteer child frame, then inspect its attributes or use the Frame to query embedded content.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Call await frame.frameElement() to get the DOM element that hosts a Puppeteer Frame. The returned value is an ElementHandle; use it to inspect iframe attributes or interact with the iframe element. To query the embedded document, use the Frame itself instead.

Get the iframe element from a Frame

When you already have a child Frame, call its frameElement() method:

As an Amazon Associate I earn from qualifying purchases.

const iframeElement = await frame.frameElement();

The result is an ElementHandle for the element in the parent document that hosts that frame. For example, read the iframe’s name attribute with evaluate:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const name = await iframeElement.evaluate(el => el.getAttribute('name'));

Puppeteer’s Frame API documents this method and demonstrates reading the host element’s name: Frame.frameElement().

Find a frame by its iframe name

Use page.frames() to get the page’s current frames, then inspect each frame’s host element. Once you find the matching host, use the Frame to query the embedded document:

const frames = page.frames();
let targetFrame = null;

for (const frame of frames) {
  const iframeElement = await frame.frameElement();
  const name = await iframeElement.evaluate(el => el.getAttribute('name'));

  if (name === 'myframe') {
    targetFrame = frame;
    break;
  }
}

if (targetFrame) {
  const text = await targetFrame.$eval('.selector', element => element.textContent);
  console.log(text);
} else {
  console.error('Frame with name "myframe" not found.');
}

This searches by the iframe’s name attribute, not by the embedded page’s content. If your page may not have loaded its frames yet, wait for the relevant page state before enumerating them.

Frame versus iframe ElementHandle

These objects point to different parts of the page:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Frame represents the embedded browsing context. Use frame methods such as frame.$() or frame.$eval() to query elements inside its document. See the Frame API.
  • frame.frameElement() moves from a child Frame to the outer DOM element that hosts it.
  • iframeElement.contentFrame() moves in the opposite direction, from the iframe’s element handle to its associated Frame. The API reference documents the specialized iframe-element signature as returning Promise<Frame>: ElementHandle.contentFrame().

For example, start with an iframe element and retrieve its frame like this:

const iframeElement = await page.$('iframe#myframe');
if (iframeElement) {
  const frame = await iframeElement.contentFrame();
  // Use frame methods to query the embedded document.
}

The null check handles the case where the selector matches no element. If the handle is not an iframe associated with a frame, do not assume it will produce a usable frame.

Know which frames have a host element

A page exposes its main frame through page.mainFrame() and child frames through the frame tree, including Frame.childFrames(). The main frame has no hosting iframe element in the normal parent-child sense: Puppeteer documents that the main frame and detached frames have no parent frame. The host-element operation is therefore intended for child frames. See the Frame API reference.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Handle navigation and detachment

A frame or element handle is tied to a live page context. Puppeteer documents that element handles are automatically disposed when their associated frame navigates away or their parent context is destroyed. If navigation, removal, or frame detachment can occur while your code is running, avoid keeping the handle for later use; reacquire the frame and element after the page reaches the state you need. The ElementHandle API describes handle lifetime.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The official API pages surfaced for this method identify the Frame reference as Puppeteer 25.12.0 and the ElementHandle.contentFrame() reference as 25.10.0. These are the versions shown on those pages, not evidence of when either method was first introduced.

Or skip the browser setup

If your goal is to capture a page rather than inspect its iframe DOM, ScreenshotNeo can return a screenshot or PDF with one GET request. Its cookie and consent handling removes supported consent banners, newsletter popups, and chat widgets before capture; failed loads, bot checks, blank pages, and cache hits are not billed. An MCP server lets AI agents use its screenshot tools. The free plan includes 1,000 screenshots a month with no card, and paid plans start at $5 for 3,000.

cURL example:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for request options. ScreenshotNeo is a website screenshot API and MCP server by Yorker Media: ScreenshotNeo. Sign up for 1,000 free screenshots a month, with no card required.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.