Waituntil Option in Playwright
On This Page What Does the waitUntil Option in Playwright Navigation Do?May 28, 2026 · 14 min read · Tool Comparison
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. Common waitUntil Options in Playwright 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. 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: 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: 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. 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. 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. 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: 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. 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. Under the punk:Playwright mind for the DOMContentLoaded event, which discharge when the HTML parser has complete building the DOM structure. When it completes: 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. 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. 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: 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. 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. 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: 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. 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: 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. 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. The about common place to use waitUntil is with (): You can also use it with other pilotage methods: Playwright permit you pass an array of events if you need to expect for multiple conditions: 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. For a blog or documentation site where all content is in the initial HTML: 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. For a React, Vue, or app that fetch datum after interpretation: 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. For a marketing page where ocular elements affair: If you & # 8217; re occupy screenshots for visual examination, you ask all images laden. payload insure the page look exactly as users see it. When you alone care about where navigation ends up: 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. For pages that show loading states or success messages after form submission: After form submission triggers navigation, networkidle ensures any success substance charge via API is ready before you assert on it. 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: Also Read: 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: What to use instead: The key is unite waitUntil with these point waits to match your application & # 8217; s actual load behavior. 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: 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. Tool Comparisons: On This Page # Ask-and-Contributeabout this theme with our Discord community. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.Waituntil Option in Playwright
Overview
What Does the waitUntil Option in Playwright Navigation Do?
javascriptawait page.goto (& # 8216; https: //example.com & # 8217;, {waitUntil: & # 8216; load & # 8217;});How Do the Different waitUntil Values Behave Under the Hood?
1. load
await page.goto (& # 8216; https: //example.com & # 8217;, {waitUntil: & # 8216; load & # 8217;});rag have downloaded their picture
stylesheets are parsed and applied2. domcontentloaded
await page.goto (& # 8216; https: //example.com & # 8217;, {waitUntil: & # 8216; domcontentloaded & # 8217;});3. networkidle
await page.goto (& # 8216; https: //example.com & # 8217;, {waitUntil: & # 8216; networkidle & # 8217;});4. commit
await page.goto (& # 8216; https: //example.com & # 8217;, {waitUntil: & # 8216; commit & # 8217;});Why Choosing the Correct waitUntil Matters in Test Automation and Scraping
How To Apply waitUntil in Playwright Code (With Examples)
1. Basic Navigation with waitUntil
await page.goto (& # 8216; https: //example.com & # 8217;, {waitUntil: & # 8216; load & # 8217;});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
await page.goto (& # 8216; https: //example.com & # 8217;, {waitUntil: [& # 8216; load & # 8217;, & # 8216; networkidle & # 8217;]});Scenario 1: Static Content Website
await page.goto (& # 8216; https: //blog.example.com/article & # 8217;, {waitUntil: & # 8216; domcontentloaded & # 8217;}); await page.locator (& # 8216; h1 & # 8217;) .textContent ();Scenario 2: Single-Page Application (SPA)
await page.goto (& # 8216; https: //app.example.com/dashboard & # 8217;, {waitUntil: & # 8216; networkidle & # 8217;}); await page.locator (& # 8216; .user-stats & # 8217;) .isVisible ();Scenario 3: Image-Heavy Landing Page
await page.goto (& # 8216; https: //example.com/product & # 8217;, {waitUntil: & # 8216; load & # 8217;}); await page.screenshot ({path: & # 8216; product-page.png & # 8217;});Scenario 4: Checking Redirects
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-urlScenario 5: Form Submission with Dynamic Feedback
await page.locator (& # 8216; button [type= & # 8221; submit & # 8221;] & # 8217;) .click (); expect page.waitForURL (& # 8216; /success & # 8217;, {waitUntil: & # 8216; networkidle & # 8217;}); * *Common Pitfalls When Using waitUntil and How To Avoid Them
When waitUntil Alone Is Not Enough and What to Use Instead
How Device and Network Conditions Affect waitUntil
Conclusion
Utile Resources for Playwright
Related Guides
Automate This With SUSA
Test Your App Autonomously