Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
FREEDOM251

Freedom251 › Blog › browser automation

How to Get the Title of a Frame in Puppeteer

By Freedom251 Team · · 3 min read

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

Use await frame.title() to read the title of a specific Puppeteer frame. For the page’s main frame, use await page.title(); it does not return a child iframe’s title.

Get the title from a specific frame

Once you have the Puppeteer Frame object, call its asynchronous title() method and await the returned promise:

As an Amazon Associate I earn from qualifying purchases.

const title = await frame.title();

The method returns a Promise<string>. The Puppeteer Frame API reference documents Frame.title() as returning the frame’s title.

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

Get the main page’s title instead

If you want the title of the top-level page rather than an iframe, use:

const title = await page.title();

Puppeteer documents Page.title() as a shortcut for page.mainFrame().title(). It therefore reads the main frame, not an arbitrary child frame. See the Page.title() reference.

Find the frame you need

A page can contain multiple frames, including nested frames. Use page.frames() to inspect attached frames, or traverse from page.mainFrame() with childFrames(). Choose a condition that uniquely identifies the frame for your page; the URL substring below is only an example.

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
const frame = page.frames().find(frame => frame.url().includes('/embedded/'));

if (!frame) {
  throw new Error('Target frame not found');
}

const title = await frame.title();
console.log(title);

The Frame API reference describes frame relationships and shows how to inspect a frame’s associated iframe element. A frame’s name or the iframe element’s selector is not itself the frame’s title: first identify the right Frame, then call title().

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

Wait when the frame appears later

If the target frame is added after navigation or page setup, wait for it rather than searching too early. page.waitForFrame() resolves with a matching frame:

const frame = await page.waitForFrame(frame => frame.url().includes('/embedded/'));
const title = await frame.title();

Replace the URL test with the condition that fits your page. Consult the Page.waitForFrame() reference for the method’s current API details.

Use frame-scoped evaluation only when needed

You can also read the document title in that frame’s execution context:

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 title = await frame.evaluate(() => document.title);

Frame.evaluate() runs in the selected frame. For this specific task, frame.title() is clearer and avoids writing a separate DOM evaluation.

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

Troubleshoot common mistakes

  • You got the outer page’s title. page.title() reads the main frame. Find the child frame and call frame.title().
  • The value is a promise, not a string. Both title methods are asynchronous; use await or handle the returned promise before using the value.
  • The frame lookup returns nothing. The frame may not be attached yet, or the matching condition may not uniquely match it. Verify the frame URLs with page.frames(), refine the condition, or wait with page.waitForFrame().
  • The title is from the wrong embedded document. Pages can have nested frames. Search all attached frames or traverse the frame tree instead of assuming the iframe is a direct child.

Match the documentation to your Puppeteer version

The current official reference pages surfaced for this API do not all show the same version: Frame.title() is documented on a page identifying Puppeteer 25.8.0, Page.title() and the Frame class pages identify 25.12.0, and Page.waitForFrame() identifies 25.9.0. Check the documentation for the version installed in your project before relying on version-specific details.

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

Or skip the browser setup

If you need a screenshot rather than programmatic access to a frame title, ScreenshotNeo provides a website screenshot API. See the ScreenshotNeo documentation for parameters and options.

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

ScreenshotNeo accepts cookie and consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and responses include X-Page-Verdict and X-Billed headers. Its MCP server includes tools for AI agents to take screenshots, get page information, and capture PDFs. The free plan includes 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots.

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

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

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.

browser automationiframesJavaScriptPuppeteer

Leave a Reply

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

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.

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