Use page.waitForFunction() when you need Puppeteer to wait for an arbitrary condition evaluated in the page, such as a status value changing to “Ready.” Puppeteer rechecks the predicate until it returns a truthy value or the wait ends. If you only need an element to appear or become visible, use page.waitForSelector(); for an element interaction, a locator is often the better fit.
Wait for an arbitrary page condition with waitForFunction()
waitForFunction() evaluates a function in the browser page context and resolves when its result is truthy. For example, to wait until an application writes a ready state into a DOM attribute:
await page.waitForFunction(() => {
const status = document.querySelector('[data-status]');
return status?.textContent === 'Ready';
});
Choose a predicate that represents the state your script actually needs. A non-empty element, a changed page value, or a particular application status can each be expressed as a condition; merely waiting for a fixed number of milliseconds does not establish that the application is ready.
Pass Node.js values as arguments
The function runs in the page, not in your Node.js scope. It cannot simply close over a local Node variable. Pass values after the options object instead:
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstall#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
const selector = '.result';
await page.waitForFunction(
selector => Boolean(document.querySelector(selector)),
{},
selector,
);
The first argument is the page function, the second is the wait-options object, and subsequent arguments are passed to the function in the browser. The page function may also be asynchronous. Treat it as a repeated condition check: avoid putting one-time side effects in it, since Puppeteer may evaluate it more than once before it succeeds.
Choose the wait that matches the condition
| What you need to wait for | Use | What it expresses |
|---|---|---|
| A general page value or predicate becomes truthy | page.waitForFunction(fn, options, ...args) |
A browser-side condition, not limited to a particular element state. |
| A matching selector exists in the DOM | page.waitForSelector(selector) |
Selector presence; it resolves immediately if the match is already there. |
| A matching element must be visible | page.waitForSelector(selector, { visible: true }) |
Presence and visibility. |
| A matching element must become absent or hidden | page.waitForSelector(selector, { hidden: true }) |
Hidden state; it can resolve with null when the selector is absent. |
| A condition is a precondition for interacting with an element | page.locator(...) |
A locator can wait for relevant element states and then perform an action. |
Use the narrowest API that describes the requirement. A selector wait is clearer than a general predicate when presence or visibility is all that matters. Puppeteer’s current guide recommends locators for selecting and interacting with elements; a locator can also use a function to wait for a custom element-related condition:
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
const paragraphs = await page
.locator(() => {
const items = document.querySelectorAll('p');
if (items.length >= 3) {
return [...items].map(item => item.textContent);
}
})
.wait();
This waits until at least three paragraphs exist and returns their text. When the goal is a page-level value or predicate rather than selecting an element for an action, waitForFunction() is usually the more direct expression.
Set a timeout or cancel a wait
The documented default wait timeout is 30,000 ms (30 seconds) in Puppeteer 25.12.0. Set a method-level timeout when one condition needs a different limit, or set a page-wide default with Page.setDefaultTimeout(). Passing timeout: 0 disables the timeout; do so only when an indefinite wait is intentional, because a condition that never becomes true can leave the script waiting indefinitely.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
await page.waitForFunction(
() => document.querySelector('[data-status]')?.textContent === 'Ready',
{ timeout: 10_000 },
);
Wait options also support an AbortSignal, so a caller can cancel a wait. For example, create an AbortController, pass its signal in the options, and call abort() when the surrounding task should stop waiting. Check the API for your installed Puppeteer version if you need exact cancellation behavior or signatures.
Troubleshoot a condition that does not resolve
- The wait times out: Check that the condition can become truthy in the page or frame being inspected. Verify the selector, expected text or value, and whether the application actually updates that state. Increase the timeout only if the operation legitimately needs more time.
- The predicate cannot see a Node variable: The callback executes in the browser context. Pass the value after the options object as an argument instead of relying on a Node.js closure.
- The selector is present but the wait still does not represent readiness: Default
waitForSelector()waits for DOM presence, not visibility or application readiness. Usevisible: truefor visibility or a predicate tied to the actual ready state. - The script hangs indefinitely: Check whether
timeout: 0was set or the page default was changed. Restore a finite timeout, or use an abort signal when the caller must be able to cancel. - The predicate behaves inconsistently: Make it a repeatable observation that returns a truthy result only when the required state is true. Do not use it to perform an action that should happen once.
A condition wait is generally preferable to a fixed sleep when the requirement is a state change: it can finish as soon as the predicate passes, while a sleep only waits for elapsed time and does not confirm the condition.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Or skip the browser setup
If your goal is a screenshot rather than browser automation, ScreenshotNeo can return a screenshot or PDF from one request. It handles cookie banners, newsletter popups and chat widgets before capture; those cleanup steps can each be turned off. Bot checks, blank pages, timeouts, failed loads and cache hits are not billed, and response headers report the page verdict and billing status.
For example, the cURL request below captures Stripe as a WebP image:
Recommended Free Tools
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 also provides an MCP server with take_screenshot, get_page_info and capture_pdf tools for Claude, Cursor and other MCP clients. The Free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 screenshots. Sign up for the free plan.
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Version note
The Puppeteer documentation consulted for this guide is marked version 25.12.0. Use the documentation and types for the Puppeteer version installed in your project if it differs, particularly for locator behavior, options and cancellation.
Frequently Asked Questions
Does Puppeteer wait for the condition immediately if it is already true?
Yes. A successful condition need not wait for a later change; the wait resolves when evaluation produces a truthy result.
Should I use a sleep instead of a condition wait?
Use a sleep only when elapsed time itself is what you need to wait for. If you need a particular page state, express that state as a condition.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Quick Recap
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.

