DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk6 min

How to Wait for a Page Condition in Puppeteer

Use selector waits for DOM state, predicates for custom conditions, locators for actions, and navigation waits for page transitions.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the wait that matches the condition your code needs: use page.waitForSelector() for an element’s DOM or visibility state, page.waitForFunction() for a custom page condition, a locator for interaction readiness, and page.waitForNavigation() for navigation. These waits are not interchangeable.

Choose the right Puppeteer wait

API Condition observed Use it when Important distinction
page.waitForSelector() A selector enters or leaves the DOM; optionally, it becomes visible or hidden You need a known element state Presence alone does not mean the element is ready to interact with. Puppeteer API reference
page.waitForFunction() A page-context predicate becomes truthy You need to wait for application-specific state The callback runs in the browser context; pass Node-side values as arguments. Puppeteer API reference
Locator wait or action An element is available for a locator operation; an action checks its preconditions You intend to interact with an element Locators can wait for action readiness rather than making you manage a handle and checks separately. Page interactions guide
page.waitForNavigation() A navigation or reload completes A click or other action is expected to navigate Start the wait before triggering the action. Puppeteer API reference

Wait for an element to appear, become visible, or disappear

For DOM presence, call waitForSelector(). If the selector already matches when the call begins, the promise resolves immediately; otherwise Puppeteer waits for it. By default, the wait checks presence, not visibility.

As an Amazon Associate I earn from qualifying purchases.

const result = await page.waitForSelector('.result', { timeout: 10_000 });

Use visible: true when the element must be in the DOM and not styled with display: none or visibility: hidden. This visibility check does not establish that the element is enabled, unobstructed, or ready for every action.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
await page.waitForSelector('.result', { visible: true });

Use hidden: true when an element should disappear or become hidden. If it is absent from the DOM, the hidden wait resolves to null.

#1 Best Overall
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB | 1920×1080 LED Monitor, 4ms GtG, Adaptive Sync, HDMI 1.4, Tilt Adjust, Low Blue Light, 4yr Advance Replacement Warranty
  • CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
  • WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
  • A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents
await page.waitForSelector('.spinner', { hidden: true });

These selector waits return an element handle when a matching element is found; a hidden wait can instead resolve to null. A missing selector in a normal wait throws after the configured timeout. The API reference documents a default timeout of 30 seconds. You can pass a task-specific timeout, use timeout: 0 to disable the timeout, configure a page default with Page.setDefaultTimeout(), or provide an AbortSignal to cancel a selector wait.

Wait for a custom page condition

Use page.waitForFunction() when the desired state cannot be expressed as a selector visibility change—for example, when a minimum number of rows must render. Puppeteer repeatedly evaluates the callback in the page context until it returns a truthy value.

await page.waitForFunction(() => document.querySelectorAll('.row').length >= 3);

The page callback cannot close over variables in Node.js. Supply values as arguments instead:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB
  • CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
  • SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
const selector = '.foo';
await page.waitForFunction(
  selector => !!document.querySelector(selector),
  {},
  selector,
);

Keep the predicate focused on the state your next step actually needs. If that state can be observed directly, an arbitrary fixed sleep may wait too little on a slow run and waste time on a fast one. See the waitForFunction() API reference for its options.

Wait until an element is ready for an action

If the goal is to click or otherwise interact, prefer a locator. Puppeteer recommends locators for selecting and interacting with elements. Locator actions wait for the element and check action preconditions; for a click, these include visibility, enabled state, viewport placement, and a stable bounding box.

await page.locator('button').click();

A locator can also wait without performing an action, for example await page.locator('.loading').wait(). A locator action is often a better fit than waiting for a selector, taking a handle, and then separately trying to make that handle actionable. The interaction guide describes locator behavior.

Rank #3
Sale
Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
  • Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
  • Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
  • Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
  • In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
  • Ultra-thin bezels: Maximize your viewing experience with thin bezels.

Wait for navigation after clicking

When a click is expected to navigate, begin waiting for navigation before triggering the click. Await both promises together so the navigation event is not missed:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const [response] = await Promise.all([
  page.waitForNavigation(),
  page.click('a.my-link'),
]);

You can use a locator click as the action in the same pattern:

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

waitForNavigation() waits for navigation, not merely for a selector to appear. Its documented default timeout is 30 seconds and its default waitUntil condition is load; configure its navigation options for the completion event your task requires. History API URL changes count as navigation. A client-rendered page can change without a document navigation, so wait for the resulting selector or application condition instead. See the navigation API reference.

Rank #4
Sale
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor | 100Hz, Game Mode, Advanced Eye Comfort, HDMI and D-sub Ports (LS27D366GANXZA)
  • CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
  • SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
  • MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
  • KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
  • INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient

Choose the right frame or element context

If the target belongs to a frame, use that frame’s selector wait as appropriate. The Frame.waitForSelector() reference (version 25.10.0) documents that the wait works across navigations. By contrast, ElementHandle.waitForSelector() is scoped to the current element; it does not work across navigation and can fail if that element detaches. When navigation may replace the document, prefer the page or frame method over a handle-scoped wait.

Check the versioned references for your installed Puppeteer version: the cited main Page API references are version 25.12.0, while the Frame selector reference is version 25.10.0. The official references can change as Puppeteer evolves. Frame selector API · ElementHandle selector API

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

Troubleshoot waits that time out or behave unexpectedly

  • The wait times out although the page looks loaded: verify that the selector actually matches the rendered DOM and that it is in the page or frame where the wait is running. For an application-specific state, use a predicate that measures that state rather than assuming a navigation event means rendering has finished.
  • A selector wait resolves but a click fails: default selector waiting checks presence only. Request visibility if that is what you need, or use a locator action for interaction preconditions.
  • A hidden wait returns null: this is expected when the selector is absent. A hidden wait succeeds when the element is absent or hidden.
  • A click completes but the navigation wait times out: the action may have updated the page without navigating, or the expected navigation may not have occurred. Wait for the resulting DOM or application state if that is the true completion condition.
  • The navigation wait misses a fast transition: register it before the click, using Promise.all() as shown above.
  • A wait stalls or behaves differently after navigation: check whether it is scoped to an ElementHandle that detached. Use the page or frame selector wait if the document can be replaced.
  • The timeout is too short or unnecessarily long: set a timeout appropriate to the task, configure the page default where suitable, or set selector-wait timeout to zero only if an unbounded wait is intentional. Selector and navigation waits have documented defaults; do not assume every wait method shares identical options.
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 task is to capture a page rather than automate an interaction, ScreenshotNeo returns a screenshot with one GET request. For example, using cURL:

Best Value
Sale
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
  • 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
  • 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.
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. Before capture, it accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each of those steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, with response headers indicating the page verdict and billing status. Its MCP server provides screenshot and PDF tools for AI agents. The Free plan includes 1,000 shots a month with no card; paid plans start at $5 for 3,000 shots.

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

Frequently Asked Questions

Does waitForSelector() wait for an element that already exists?

Yes. It resolves immediately when the selector already matches at the time of the call.

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.

Can a Puppeteer page condition wait detect a client-side update without navigation?

Yes. Use a selector wait or a waitForFunction() predicate for the resulting page state; waitForNavigation() is for navigation.

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
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.