Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk4 min

How to Find Child Frames in Puppeteer

Get direct child frames with page.mainFrame().childFrames(), traverse nested frames recursively, or use page.frames() for every frame attached to a Puppeteer page.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use page.mainFrame().childFrames() to get the main frame’s direct child frames. To include nested descendants, recursively visit each frame’s childFrames(); to get a flat list of every frame currently attached to the page, use page.frames().

Choose the method that matches the frame scope

Need Method What it returns
Direct children of the main frame page.mainFrame().childFrames() Immediate child frames only
Descendants at any nesting depth Recursively call childFrames() All descendants, excluding the starting frame
Every currently attached frame page.frames() A flat array that includes the main frame

These methods are documented in the Frame.childFrames(), Frame, and Page references.

As an Amazon Associate I earn from qualifying purchases.

Get the main frame’s direct child frames

Once you have a Puppeteer Page, call mainFrame() and then childFrames():

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const childFrames = page.mainFrame().childFrames();

for (const frame of childFrames) {
  console.log(frame.url());
}

This is a one-level lookup. If a child frame contains its own iframe, that nested frame is not included in this array.

Find nested child frames recursively

Walk each child’s descendants to collect every nested frame below the main frame:

function collectFrames(frame) {
  return frame.childFrames().flatMap(child => [child, ...collectFrames(child)]);
}

const childFrames = collectFrames(page.mainFrame());

for (const frame of childFrames) {
  console.log(frame.url());
}

The result includes all descendants and excludes the main frame itself. For a recursive traversal that also processes frames as it visits them, use:

Rank #2
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option
function visitChildFrames(frame, visit) {
  for (const child of frame.childFrames()) {
    visit(child);
    visitChildFrames(child, visit);
  }
}

visitChildFrames(page.mainFrame(), frame => {
  console.log(frame.url());
});

Puppeteer’s official Frame documentation demonstrates traversing the frame tree using childFrames().

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

List all frames attached to the page

If you do not need to distinguish parent and child relationships, use page.frames():

const frames = page.frames();

for (const frame of frames) {
  console.log(frame.url());
}

This is a flat list of all frames currently attached to the page, including the main frame. Filter or inspect the list when you need a page-wide search rather than traversal from a particular parent.

Identify a frame by its iframe element

If you know an iframe’s name attribute, the Frame reference documents finding the associated frame by inspecting each frame’s element:

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
const targetFrame = await (async () => {
  for (const frame of page.frames()) {
    const element = await frame.frameElement();
    const name = await element.evaluate(el => el.getAttribute('name'));

    if (name === 'checkout') {
      return frame;
    }
  }
})();

if (targetFrame) {
  console.log('Found:', targetFrame.url());
}

Use the returned Frame object for work inside that frame. A frame-scoped query, for example, is await targetFrame.$eval('h1', el => el.textContent). The frame element identifies the iframe in its parent document; the frame object is the context for querying or evaluating in the frame’s own document.

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

Use the parent relationship when traversing upward

Call frame.parentFrame() to get a frame’s parent. It returns null for the main frame and for a detached frame. See the official Frame.parentFrame() reference.

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

Account for frame lifecycle changes

A page’s frame tree changes as frames attach, navigate, or detach. If the target may be created or removed during page activity, collect or refresh frame references after the relevant change rather than assuming an earlier list is current. Puppeteer documents these lifecycle events in its Frame reference.

When reading or evaluating page content, use the specific frame object. Puppeteer notes: “When JavaScript is executed in a frame, the JavaScript does not affect frames inside the ambient frame the JavaScript executes in.” Evaluating in the main frame does not automatically query nested frame documents.

Or skip the browser setup

If your goal is a screenshot rather than frame inspection, ScreenshotNeo can return one with a GET request, without setting up Puppeteer:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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. It accepts cookie and consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each cleanup step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the page verdict and billing status in headers. Its MCP server provides screenshot tools for AI agents and other MCP clients. The free plan includes 1,000 screenshots per month with no card required; paid plans start at $5 for 3,000 screenshots.

Sign up for 1,000 free screenshots a month, with no card.

Troubleshoot common frame lookup problems

  • A nested frame is missing: childFrames() returns immediate children only. Recurse through each child or use page.frames() for a flat page-wide list.
  • The frame is not in the list: It may not have attached yet, or it may have detached. Refresh the list after the page’s frame lifecycle changes.
  • A query does not find content inside an iframe: Run the query against the frame’s Frame object, not the main frame’s document. Use a frame-scoped method such as frame.$eval().
  • parentFrame() returns null: That is expected for the main frame; the method also returns null for a detached frame.

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.

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
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

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.