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 desk4 min

How to Wait for Navigation in a Puppeteer Frame

Use frame.waitForNavigation() on the frame that will change, and start the wait alongside the action that triggers it. Learn when to wait for a selector instead.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Call frame.waitForNavigation() on the frame expected to navigate, and arm it at the same time as the action that triggers navigation. This avoids missing a fast navigation:

const [response] = await Promise.all([
  frame.waitForNavigation(),
  frame.click('a.my-link'),
]);

The promise resolves with the main resource response, or null when there is no such response, as with some History API navigations. Puppeteer documents the method and this concurrent-wait pattern.

As an Amazon Associate I earn from qualifying purchases.

Choose the frame that will navigate

Puppeteer represents DOM frames, including <iframe> elements, with its Frame class. A page can contain nested frames. Use the frame whose document or URL is expected to change; a page-level navigation wait is for navigation of the main frame, not a substitute for waiting on a child frame.

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

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

For a known iframe, obtain its frame from the page’s frame tree and verify you have the intended one before triggering the action. Frame attachment, navigation, and detachment events are dispatched on the parent page. See Puppeteer’s Frame reference.

Wait for navigation without a race

Put the navigation wait and the click or other triggering action in the same Promise.all. Do not await the click first and start waiting afterward: the navigation may already have begun by then.

const [response] = await Promise.all([
  frame.waitForNavigation({ waitUntil: 'domcontentloaded' }),
  frame.click('a.my-link'),
]);

console.log(response ? response.url() : 'Navigation had no main-resource response');

Choose a lifecycle condition based on what the next step needs. domcontentloaded waits for the document’s DOM content to be parsed; it does not guarantee that application-specific asynchronous work or a particular interface element is ready. If the next operation depends on a specific UI state, wait for that state after navigation.

Puppeteer treats a URL change made with the History API as navigation. Consequently, a successful waitForNavigation() does not necessarily mean a new document was loaded, and its result can be null. The official method reference describes the navigation options and return value.

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

When to wait for an element instead

Navigation and readiness are different conditions. If the requirement is “continue when this element appears,” wait for the element rather than assuming navigation is the signal you need.

Frame-level selector wait

await frame.waitForSelector('.results-ready', { visible: true });

Frame.waitForSelector() can wait across navigations, making it suitable when the target element may appear in the frame’s next document. It throws if the element does not appear before the timeout. Its options include visible, hidden, signal, and timeout; the documented default timeout is 30,000 milliseconds and can be changed with Page.setDefaultTimeout(). Check the Frame.waitForSelector reference and WaitForSelectorOptions reference for the installed version.

Locator for an interaction

For selecting and interacting with an element, Puppeteer’s current interaction guidance recommends locators. Locator actions automatically wait for element presence and the appropriate state, which can remove the need for a separate low-level selector wait in common interaction flows. Use waitForSelector() when its explicit wait behavior is what the task requires. See the Page interactions guide.

Do not carry an element handle across navigation

A selector wait on Frame is different from ElementHandle.waitForSelector(): the latter is tied to the existing element context and does not work across navigation or after that element is detached. Start a fresh frame-level wait or reacquire the element after navigation. See the ElementHandle.waitForSelector reference.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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

Troubleshooting frame navigation waits

  • The wait times out although the click worked: confirm that the clicked link navigates the same frame you passed to waitForNavigation(). If the page updates content without navigation, wait for a selector or application-specific condition instead.
  • The wait misses a fast navigation: start it in Promise.all with the triggering action; do not start it after the click resolves.
  • The wait resolves but the element is missing: navigation completion is not proof that asynchronous application work has finished. Add a frame-level selector wait for the element the next step requires.
  • The response is null: this is an allowed result, including when the URL changes through the History API. Do not treat a null response alone as evidence that the wait failed.
  • A selector wait fails after a redirect or frame replacement: avoid relying on an old ElementHandle; use the relevant Frame and reacquire the target after navigation.
  • Method options or types do not match examples: check the installed Puppeteer version. The current references consulted identify versions 25.9.0 for Frame.waitForNavigation, 25.10.0 for Frame.waitForSelector, and 25.12.0 for Frame and interaction documentation; APIs may differ across installed releases.
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 your goal is simply to capture a page rather than automate navigation inside its frame tree, ScreenshotNeo offers a one-request screenshot API:

Best Value
The SQL Programming Language: .
  • Used Book in Good Condition
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. Cookie banners, popups, and chat widgets are removed before the shot; bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots. The free plan includes 1,000 screenshots a month with no card, and paid plans start at $5 for 3,000. Sign up for free.

Frequently Asked Questions

Does a History API URL change count as navigation in Puppeteer?

Yes. Puppeteer’s Frame.waitForNavigation documentation treats History API URL changes as navigation.

What does waitForNavigation return?

It resolves to the main resource response or null, depending on the navigation.

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.

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
Outdated Drivers Are Slowing You DownFree scan - exact matches

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.