Waituntil Option in Playwright

On This Page What Does the waitUntil Option in Playwright Navigation Do?May 28, 2026 · 14 min read · Tool Comparison

Waituntil Option in Playwright

Ever follow your Playwright examination fail with a timeout error, even though the page clearly laden in forepart of you?

I had the same frustration. My tryout worked locally but failed in CI grapevine constantly. The perpetrator?

I was using the nonremittal waitUntil setting, which didn & # 8217; t match how my application really laden.

The waitUntil option tells Playwright when to consider navigation complete. But & # 8220; complete & # 8221; means different things reckon on your page & # 8217; s behavior.

A single-page app that fetches data asynchronously needs a different strategy than a static HTML page. Playwright gives you four alternative, each designed for different load behaviors.

Overview

Common waitUntil Options in Playwright

  • load: Waits for the page & # 8217; s load event, ensuring all resources, including images and scripts, are fully loaded. Use this when you need the entire page, visual and functional elements included, to be ready.
  • domcontentloaded: Waits until the HTML is fully parsed and the DOM is ready, without waiting for images or stylesheets. Ideal for chop-chop interacting with elements present in the initial HTML.
  • networkidle: Waits until there are no ongoing network asking for a short period, typically 500ms. This is utile for pages that fetch message dynamically, check asynchronous data has laden.
  • commit: Waits for seafaring to be committed, signify the response headers are get and session history updated. This is the earliest point at which Playwright considers navigation started, before rendering or imagination loading.

In this clause, I & # 8217; ll show you how each value work, when to use which one, and how to fix timing issues in your trial.

What Does the waitUntil Option in Playwright Navigation Do?

The waitUntil alternative is a parameter you surpass to Playwright & # 8217; s piloting method like page.goto (), page.reload (), and page.goBack (). It tells what condition to wait for before considering the navigation successful and moving to the next line of code.

Without this selection, Playwright uses a nonremittal waiting strategy that might not couple your page & # 8217; s actual loading behavior. This mismatch is what get those frustrating timeout errors or untimely interactions with uncompleted pages.

Here & # 8217; s the basic syntax:

javascriptawait page.goto (& # 8216; https: //example.com & # 8217;, {waitUntil: & # 8216; load & # 8217;});

When you set waitUntil, you & # 8217; re fundamentally respond the enquiry: & # 8220; When is this page ready for me to interact with it? & # 8221; The answer depends entirely on what your page do during load.

Read More:

What Happens During Navigation

To translate why waitUntil matters, you demand to cognize what happens when a browser loads a page:

  1. Navigation commits: The browser receive reply headers and updates the session history
  2. HTML parsing begins: The browser starts build the DOM tree from the HTML
  3. ready: The HTML is fully parse (this triggers DOMContentLoaded event)
  4. Resources lading: Images, stylesheets, typeface, and scripts download and execute
  5. Page load complete: All resources finish loading (this spark the load event)
  6. Async activity: JavaScript may continue making API calls and updating the page

Traditional page loads follow this successiveness linearly. But modernistic web apps often interpret initial content quickly, so bring data asynchronously. This is where choosing the right waitUntil value turn critical.

If you wait for load on a app that fetches information after rendering, you might interact with the page before the datum appears. If you wait for networkidle on a page with unremitting analytics pings, you & # 8217; ll wait forever.

The waitUntil option gives you control over which point in this lifecycle Playwright should consider & # 8220; done. & # 8221;

The waitUntil option gives you control over which point in this lifecycle Playwright should consider & # 8220; done. & # 8221; But choose the right strategy requires testing under realistic conditions. BrowserStack & # 8217; s cloud infrastructure let you run Playwright tests with mesh throttling and performance monitoring to formalize your waitUntil choices before they impact product.

How Do the Different waitUntil Values Behave Under the Hood?

Each waitUntil value corresponds to a specific browser event or mesh state. Understanding what triggers each one helps you pick the rightfield scheme for your use example.

1. load

The load option delay for the browser & # 8217; s load event to fire. This happen when the browser has finished download and processing all resources reference in the initial HTML: images, stylesheets, scripts, iframes, and fount.

await page.goto (& # 8216; https: //example.com & # 8217;, {waitUntil: & # 8216; load & # 8217;});

Under the strong-armer:Playwright heed for the window.load case. The browser discharge this case but after every resource in the page (including those in iframes) has finished loading.

When it completes:

  • All rag have downloaded their picture
  • All
    stylesheets are parsed and applied
  • All
  • All iframes feature fully loaded

What it doesn & # 8217; t wait for:requests made after the initial page cargo. If your page do a fetch () call in a useEffect crotchet or after a script executes, shipment won & # 8217; t wait for that.

2. domcontentloaded

The domcontentloaded pick waits for the browser & # 8217; s DOMContentLoaded event. This fires as soon as the HTML papers is amply parse and the DOM tree is built, without look for stylesheets, image, or subframes.

await page.goto (& # 8216; https: //example.com & # 8217;, {waitUntil: & # 8216; domcontentloaded & # 8217;});

Under the punk:Playwright mind for the DOMContentLoaded event, which discharge when the HTML parser has complete building the DOM structure.

When it completes:

  • The HTML is amply parsed
  • All DOM elements are accessible via JavaScript
  • Synchronal scripts in the HTML have accomplish

What it doesn & # 8217; t postponement for:Images, stylesheets, fonts, or async scripts. The page might look unstyled or have missing images when this resolves.

Speed advantage:This is typically 30-50 % faster than load on resource-heavy pages because it doesn & # 8217; t wait for picture or external assets.

3. networkidle

The networkidle option waits until there are no more than 2 network connections active for at least 500ms. This catches most asynchronous datum fetching that happens after the initial page loading.

await page.goto (& # 8216; https: //example.com & # 8217;, {waitUntil: & # 8216; networkidle & # 8217;});

Under the toughie:Playwright reminder all meshwork asking (XHR, fetch, resource loading) and commence a 500ms timer every clip the number of active connections drops to 2 or fewer. If no new petition start within that window, navigation is considered consummate.

When it completes:

  • Initial page resources have lade
  • API calls triggered by JavaScript have finished
  • Dynamic content fetched via AJAX is likely rendered

The 2-connection allowance:Some browsers maintain lasting connections for things like Server-Sent Events or long-polling. The 2-connection threshold prevents these from blocking indefinitely.

For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users.

Warning:Pages with continuous polling, live chat widgets, or real-time update may never make network unused. You & # 8217; ll hit the navigation timeout in these cases.

4. commit

The commit option wait only for the navigation to commit-meaning the browser has obtain the reply headers and updated the session history. This is the earliest potential point where sailing is view started.

await page.goto (& # 8216; https: //example.com & # 8217;, {waitUntil: & # 8216; commit & # 8217;});

Under the strong-armer:Playwright decide as soon as the browser receives HTTP response header and commits to navigating to the new URL. At this point, page.url () will return the new URL, but nothing has be supply yet.

When it completes:

  • Response headers obtain
  • is uncommitted
  • Session history is updated
  • The old page is gone from the viewport

What it doesn & # 8217; t wait for:Literally everything else. No HTML parsing, no DOM building, no resource loading. The page is essentially clean.

Use case:This is seldom use in test mechanization. It & # 8217; s mainly useful when you only care about piloting happening (like check redirects) or when you project to wait for specific elements manually afterward.

Why Choosing the Correct waitUntil Matters in Test Automation and Scraping

Picking the wrong waitUntil value doesn & # 8217; t just slack down your tests-it creates flaky failure that squander hr of debugging time. The right choice direct impact test reliability, execution swiftness, and data accuracy.

Here & # 8217; s what pass when you get it wrong:

  • : Using domcontentloadedon API-driven pages induce & # 8220; Element not constitute & # 8221; errors because content hasn & # 8217; t lade yet. Usingnetworkidleon page with analytics triggers 30-second timeouts on every navigation.
  • Execution Speed:Wrong choices add 2-3 seconds per page load. Across 100 tests, that & # 8217; s 3+ minutes wasted per run. Switching from load todomcontentloadedin one project cut CI time from 12 to 8 minutes-a 33 % betterment.
  • Data Accuracy in: Using domcontentloadedon JavaScript-rendered content gives you empty fields. Pages that shift from server-side to client-side supply break your scraper silently.
  • Resource Consumption: Using loadwhen you simply involve DOM downloads unnecessary image and videos. Extra delay time means high cloud examine bills and wasted bandwidth on slow networks or CI environments.

Getting these timing conclusion right the inaugural clip preserve myriad hours of debugging and re-running failed tests. BrowserStack & # 8217; s Playwright consolidation yield you detailed test logs, screenshots, and picture recordings to pinpoint exactly where your waitUntil strategy breaks down.

How To Apply waitUntil in Playwright Code (With Examples)

Now that you understand what each waitUntil value make, let & # 8217; s look at how to use them in real scenario. The key is tally the scheme to your page & # 8217; s laden behavior.

1. Basic Navigation with waitUntil

The about common place to use waitUntil is with ():

await page.goto (& # 8216; https: //example.com & # 8217;, {waitUntil: & # 8216; load & # 8217;});

You can also use it with other pilotage methods:

await page.reload ({waitUntil: & # 8216; networkidle & # 8217;}); await page.goBack ({waitUntil: & # 8216; domcontentloaded & # 8217;});
await page.goForward ({waitUntil: & # 8216; commit & # 8217;});

2. Multiple waitUntil Values

Playwright permit you pass an array of events if you need to expect for multiple conditions:

await page.goto (& # 8216; https: //example.com & # 8217;, {waitUntil: [& # 8216; load & # 8217;, & # 8216; networkidle & # 8217;]});

This waits for both the load event AND network idle. Navigation only completes when both conditions are met. This is utile when you want the security of burden but also need to get async asking.

Let & # 8217; s consider a few scenarios to better understand how you can apply waitUntil in Playwright.

Scenario 1: Static Content Website

For a blog or documentation site where all content is in the initial HTML:

await page.goto (& # 8216; https: //blog.example.com/article & # 8217;, {waitUntil: & # 8216; domcontentloaded & # 8217;}); await page.locator (& # 8216; h1 & # 8217;) .textContent ();

You don & # 8217; t need images or stylesheets to read the article rubric, so domcontentloaded is fast. The DOM is ready, and you can immediately interact with text elements.

Scenario 2: Single-Page Application (SPA)

For a React, Vue, or app that fetch datum after interpretation:

await page.goto (& # 8216; https: //app.example.com/dashboard & # 8217;, {waitUntil: & # 8216; networkidle & # 8217;}); await page.locator (& # 8216; .user-stats & # 8217;) .isVisible ();

The initial HTML is just a shell. The real content loads via API phone after JavaScript executes. networkidle ensures those fetch requests consummate before you try to interact with the information.

Scenario 3: Image-Heavy Landing Page

For a marketing page where ocular elements affair:

await page.goto (& # 8216; https: //example.com/product & # 8217;, {waitUntil: & # 8216; load & # 8217;}); await page.screenshot ({path: & # 8216; product-page.png & # 8217;});

If you & # 8217; re occupy screenshots for visual examination, you ask all images laden. payload insure the page look exactly as users see it.

Scenario 4: Checking Redirects

When you alone care about where navigation ends up:

await page.goto (& # 8216; https: //example.com/old-url & # 8217;, {waitUntil: & # 8216; commit & # 8217;}); const finalUrl = page.url ();
console.log (finalUrl); // https: //example.com/new-url

You don & # 8217; t need to wait for the page to render-just confirm the redirect happened. commit is the fastest way to check this.

Scenario 5: Form Submission with Dynamic Feedback

For pages that show loading states or success messages after form submission:

await page.locator (& # 8216; button [type= & # 8221; submit & # 8221;] & # 8217;) .click (); expect page.waitForURL (& # 8216; /success & # 8217;, {waitUntil: & # 8216; networkidle & # 8217;}); * *

After form submission triggers navigation, networkidle ensures any success substance charge via API is ready before you assert on it.

Common Pitfalls When Using waitUntil and How To Avoid Them

Even experienced Playwright users run into issues with waitUntil. These misapprehension make hard-to-debug failures that look random but postdate predictable form.

Here are the most common pitfall and how to avoid them:

  • Using networkidle on pages with continuous background activity:Pages with analytics or go chat ne'er reach network idle. Your trial times out after 30 s.Solution: Use lading, then wait for specific element.
  • Assuming load means & # 8220; ready to interact & # 8221;:The load event fires before JavaScript finishes initializing. Clicking button too early execute nothing.Solution: Wait for elements to be actionable, not just seeable.

Also Read:

  • Using domcontentloaded for JavaScript-rendered content:SPAs render empty-bellied HTML shells foremost. domcontentloaded fires before content appears.Solution: Use networkidle for SPAs, or add explicit element waits after domcontentloaded.
  • Not calculate for third-party script: Ads and track scripts load slowly. Using load makes exam hang look for international resources.Solution: Use domcontentloaded or block third-party scripts with route manager.
  • Ignoring different behaviour across environments: Pages hit networkidle quickly locally but timeout in CI with slow networks.Solution: Increase timeouts for CI or exam with realistic network conditions.
  • Using commit without additional waiting: commit resolution when the page is still clean. Any interaction fails immediately.Solution: Only use commit for checking redirects, then add waitForLoadState (& # 8216; domcontentloaded & # 8217;).
  • Not combining multiple strategies: One waitUntil value for all pages creates timeouts or premature interactions.Solution: Create page-specific helper functions with the right strategy for each page type.

When waitUntil Alone Is Not Enough and What to Use Instead

The waitUntil selection handles introductory page loading, but real applications load substance in stages, show laden spinners, or convey data after the page render. In these cases, you need more precise wait beyond just navigation events.

Sometimes waitUntil isn & # 8217; t adequate because:

  • Specific elements burden after navigation completes:Your API shout finishes after load fires, so the element you demand isn & # 8217; t visible yet
  • Loading states hide real message:The page evidence a spinner while networkidle declaration, then update with data
  • Elements exist but aren & # 8217; t interactive:Buttons are in the DOM but disabled or missing event hearer
  • Third-party widgets load separately:Chat widgets or maps initialize after the main page finishes loading
  • Content updates dynamically:Counters, timers, or text fields alter values after look in the DOM

What to use instead:

  • waitForSelector ():Wait for specific elements to appear, be visible, or be enshroud before interacting with them
  • waitForResponse ():Wait for specific API calls to complete instead of all network activity
  • waitForFunction ():Wait for custom weather like text content reaching a specific value or component converge sure criteria
  • waitForLoadState ():Chain multiple load states like waitForLoadState (& # 8216; networkidle & # 8217;) after initial pilotage
  • Locator auto-waiting:Use Playwright locater that automatically look for elements to be actionable before chatter or typing
  • Frame locater:Wait for iframe substance to load when dealing with embedded widgets

The key is unite waitUntil with these point waits to match your application & # 8217; s actual load behavior.

How Device and Network Conditions Affect waitUntil

The same waitUntil strategy behave completely differently bet on network speed and gimmick execution. On your fast WiFi with a powerful laptop, pages reach cargo and networkidle in milliseconds. But on a 3G mobile connection or a low-end Android device, that same page might take 10x long or never reach networkidle at all.

Device performance also affect JavaScript executing timing. High-end devices parse and accomplish React or Vue quickly, so domcontentloaded and full interactivity bechance most simultaneously. On dim devices or overloaded CI moon-curser, there & # 8217; s a 2-3 s gap where the DOM is ready but event listeners aren & # 8217; t attached yet.

This is where testing on real devices and network conditions becomes critical. BrowserStack lets you formalize your waitUntil strategy across real-world scenario before users encounter job.

What BrowserStack provides:

  • :Test on actual iPhones, Android phones, and pad to see how waitUntil performs on existent hardware
  • Network throttling:Simulate 3G, 4G, and slow WiFi conditions to verify your scheme works under piteous connectivity
  • Geographic dispersion:Test from different region with depart latency to get location-specific timing issues
  • :Run tests with different waitUntil values across multiple devices simultaneously to detect the optimal strategy
  • :Track consignment clip and place which waitUntil value works best for each device-network combination

Talk to an Expert

Conclusion

Choosing the rightfield waitUntil strategy is all-important for reliable tryout automation and accurate web scrape. Use load for image-heavy pages, domcontentloaded for static content, networkidle for API-driven SPAs, and commit merely for redirect checks. The wrong choice Pb to, wasted time, and incomplete data.

However, network conditions and device performance dramatically affect when navigation events fire. What work on your laptop might betray on mobile 3G or in CI environments. Use BrowserStack to screen your waitUntil strategies across real devices, browsers, and network conditions. This ensures your mechanization work reliably for actual users.

Utile Resources for Playwright

Tool Comparisons:

Tags
7,000+ Views

# Ask-and-Contributeabout this theme with our Discord community.

Related Guides

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free