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

The reliable fix is to create the waitForEvent promise before the action that emits the event. Do not await the wait while the action is still pending: store the promise, trigger the click or navigation, then await the stored promise. If that order is already correct, check the event name, whether the page or browser context owns it, predicate filtering, timeout settings, and whether teardown closed the object.

The synchronization pattern that fixes most timeouts

A fast event can happen between an action and a later listener. Install the listener first:

const downloadPromise = page.waitForEvent('download');
await page.getByText('Download file').click();
const download = await downloadPromise;

This is the order shown in the Playwright Page API documentation: “Start waiting for download before clicking. Note no await.” The first line starts listening and returns a promise; it does not wait for the download to occur. The click then causes the event, and the final line waits for the result.

The same rule applies to any event whose trigger is under your control:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Amazon Basics Wired QWERTY Keyboard, Works with Windows, Plug and Play, Easy to Use with Media Control, Full-Sized, Black
  • KEYBOARD: The keyboard works for Windows with hot keys that enable easy access to Media, My Computer, Mute, Volume up/down, and Calculator
  • EASY SETUP: Experience simple installation with the USB wired connection
  • VERSATILE COMPATIBILITY: This keyboard is designed to work with multiple Windows versions, including Vista, 7, 8, 10 offering broad compatibility across devices.
  • SLEEK DESIGN: The elegant black color of the wired keyboard complements your tech and decor, adding a stylish and cohesive look to any setup without sacrificing function.
  • FULL-SIZED CONVENIENCE: The standard QWERTY layout of this keyboard set offers a familiar typing experience, ideal for both professional tasks and personal use.
const responsePromise = page.waitForEvent('response');
await page.getByRole('button', { name: 'Save' }).click();
const response = await responsePromise;

Putting await on the first line is a deadlock:

// Wrong: execution cannot reach the click until the event has happened.
const download = await page.waitForEvent('download');
await page.getByText('Download file').click();

Use the event owner that matches what you expect

waitForEvent listens on the object on which it is called. A page wait and a browser-context wait do not observe the same scope.

Known popup opened by a page

When a specific page action opens a popup, wait on that page:

const popupPromise = page.waitForEvent('popup');
await page.getByText('open the popup').click();
const popup = await popupPromise;
await popup.waitForLoadState('domcontentloaded');

The popup event means that a new page was created by that page. It does not mean the popup’s document is ready for assertions; those are separate conditions.

New page when the creating action is unknown

If code elsewhere in the test or application can create a page, listen on the browser context:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const pagePromise = context.waitForEvent('page');
await triggerThatMayOpenAnyPage();
const newPage = await pagePromise;
await newPage.waitForLoadState('domcontentloaded');

The context-level event can collect new pages, including popups, in that context. Use the narrow page-level wait when the owner and trigger are known; use the context when the source is not.

Situation Wait on What to verify next
A button on one page opens a popup page.waitForEvent('popup') Popup URL or DOM after the event
Any code in a context may create a page context.waitForEvent('page') Which new page was created
A file is downloaded by a click page.waitForEvent('download') Suggested filename, path, or save result
An HTTP response is expected page.waitForEvent('response') URL, status, and response timing

Confirm the event name and the actual trigger

The event name must be one emitted by the object you selected, using the same kind of name accepted by that object’s on(event) listener. A click that navigates in the same tab will not produce a popup; a server-side request will not produce a download unless the browser treats the response as a download.

Rank #2
Sale
Logitech MK270 Full Size Wireless Keyboard and Mouse Combo - Black
  • Reliable Plug and Play: The USB receiver provides a reliable wireless connection up to 33 ft (1), so you can forget about drop-outs and delays and you can take it wherever you use your computer
  • Type in Comfort: The design of this keyboard creates a comfortable typing experience thanks to the low-profile, quiet keys and standard layout with full-size F-keys, number pad, and arrow keys
  • Durable and Resilient: This full-size wireless keyboard features a spill-resistant design (2), durable keys and sturdy tilt legs with adjustable height
  • Long Battery Life: MK270 combo features a 36-month keyboard and 12-month mouse battery life (3), along with on/off switches allowing you to go months without the hassle of changing batteries
  • Easy to Use: This wireless keyboard and mouse combo features 8 multimedia hotkeys for instant access to the Internet, email, play/pause, and volume so you can easily check out your favorite sites
  • Identify the browser-visible effect the application is supposed to produce.
  • Check that the event is documented for the page or context object you are using.
  • Make sure the action really reaches the code path that emits it; a disabled button, validation error, or intercepted request can prevent the event entirely.
  • Keep the listener immediately next to the trigger while diagnosing so another action cannot consume the event first.

Error text such as “Timeout 15000ms exceeded while waiting for event response” or “Timeout 90000ms exceeded while waiting for event download” identifies the wait and its deadline, not the cause. Those values are examples of user-reported messages, not a measurement of how common any failure is.

Check predicates before increasing the timeout

A predicate is an optional filter. The wait resolves only when an emitted event is passed to the predicate and the predicate returns a truthy value. If the event arrives but its URL, status, filename, or other property differs from your assumption, the promise remains pending.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const responsePromise = page.waitForEvent('response', response =>
  response.url().endsWith('/api/report') && response.status() === 200
);
await page.getByRole('button', { name: 'Generate report' }).click();
const response = await responsePromise;

For debugging, temporarily remove the predicate and inspect the first matching event:

const responsePromise = page.waitForEvent('response');
await page.getByRole('button', { name: 'Generate report' }).click();
const response = await responsePromise;
console.log(response.url(), response.status());

Then restore a predicate that reflects the observed payload. Avoid predicates that depend on unstable query strings, redirects, or a filename that the server can change unless those values are part of the contract you are testing.

Understand which timeout is being applied

waitForEvent accepts a timeout option. The Page API and BrowserContext API document a default of 0 for this wait, while other Playwright settings can still affect actions around it. Check the explicit option, the configured action timeout, and defaults set through timeout-setting methods before changing anything.

const downloadPromise = page.waitForEvent('download', { timeout: 30_000 });
await page.getByText('Download file').click();
const download = await downloadPromise;

A longer deadline is useful when the application is legitimately slow, but it cannot create an event that was missed, filtered out, emitted on another object, or prevented by application logic. Set a deliberate timeout for the condition under test and keep the trigger inside the same test step so failures remain diagnosable.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Logitech K120 Full Size Wired Keyboard USB Plug-and-Play Windows - Black
  • All-day Comfort: The design of this standard keyboard creates a comfortable typing experience thanks to the deep-profile keys and full-size standard layout with F-keys and number pad
  • Easy to Set-up and Use: Set-up couldn't be easier, you simply plug in this corded keyboard via USB on your desktop or laptop and start using right away without any software installation
  • Compatibility: This full-size keyboard is compatible with Windows 7, 8, 10 or later, plus it's a reliable and durable partner for your desk at home, or at work
  • Spill-proof: This durable keyboard features a spill-resistant design (1), anti-fade keys and sturdy tilt legs with adjustable height, meaning this keyboard is built to last
  • Plastic parts in K120 include 51% certified post-consumer recycled plastic*

For a project-wide policy, inspect your Playwright configuration and any calls to page.setDefaultTimeout() or context.setDefaultTimeout(). Verify the installed binding and version: the cited documentation is current web documentation accessed on September 29, 2026, and this article uses JavaScript/TypeScript-style examples. Other language bindings or pinned releases can expose different syntax or defaults.

Separate event arrival from page readiness

An event can resolve while the resulting page is still loading. Treat these as two waits:

const popupPromise = page.waitForEvent('popup');
await page.getByRole('link', { name: 'Open account' }).click();
const popup = await popupPromise;
await popup.waitForLoadState('domcontentloaded');
await popup.getByRole('heading', { name: 'Account' }).waitFor();

Use a selector or web assertion for the user-visible condition your test needs. The Playwright documentation discourages networkidle as a generic testing strategy; ongoing analytics, sockets, or polling can keep a page busy even when the required UI is ready. Conversely, domcontentloaded only indicates that the initial document has been parsed, not that a particular component has rendered.

Check page, context, and browser lifetime

A page-scoped wait fails if that page closes before the event arrives. A context-scoped wait fails if its context closes first. Common causes include a fixture that tears down early, a test that calls page.close(), a browser context recreated between setup and trigger, or a navigation flow that opens and closes a temporary page.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Place the wait and its trigger before fixture teardown or afterEach cleanup.
  • Log whether page.isClosed() is true at the failure point and whether the owning context is still active.
  • Do not reuse a page or context after a helper has closed it.
  • If a popup is intentionally short-lived, capture its event and inspect it before the code that closes it runs.

A repeatable diagnosis checklist

  1. Install first: store the promise, with no await, before the click, navigation, or other trigger.
  2. Verify scope: choose the page for that page’s event, or the context for any new page in the context.
  3. Verify identity: confirm the event name and that the application action actually emits it.
  4. Remove filters temporarily: inspect the raw event payload, then correct the predicate.
  5. Inspect deadlines: check explicit wait options and configured defaults, including a possible timeout of 0.
  6. Check lifecycle: ensure the page, context, and browser remain open until the wait resolves.
  7. Wait for the real outcome: after an event, use a DOM assertion or a documented load state for readiness.
  8. Reproduce with tracing or logs: record the action, event payload, URL, and close events rather than adding arbitrary sleeps.

Patterns that make waits reliable

Keep the trigger and wait together

async function downloadReport(page) {
  const downloadPromise = page.waitForEvent('download');
  await page.getByRole('button', { name: 'Download report' }).click();
  return await downloadPromise;
}

const download = await downloadReport(page);
await download.saveAs('artifacts/report.csv');

This helper makes the ordering visible and returns the event data to the assertion or file-handling code.

Use a context listener for an unknown page creator

const pagePromise = context.waitForEvent('page');
await page.getByRole('button', { name: 'Continue' }).click();
const createdPage = await pagePromise;
await createdPage.waitForLoadState('domcontentloaded');

If several pages can be created, add a predicate based on a stable URL or another documented property, and make sure that predicate cannot match an unrelated page.

Rank #4
Redragon K521 Upgrade Rainbow LED Gaming Keyboard, 104 Keys Wired Mechanical Feeling Keyboard with Multimedia Keys, One-Touch Backlit, Anti-Ghosting, Compatible with PC, Mac, PS4/5, Xbox
  • 【Dreamy Rainbow Gaming Keyboard】K521 Gaming Keyboard Adopts a Different LED Backlight Design, Upgraded on the Traditional LED Backlight Effect, Making the Light More Penetrating, Giving You a More Dazzling Visual Effect, Making Your Gaming Process More Enjoyable
  • 【One Touch Opens & Visual Feast】The K521 Red Dragon Keyboard has a One-Touch on/off Lighting Button for Added Convenience. It also has a Three-Position Adjustable Breathing Mode and a Four-Position Adjustable Brightness Lighting Mode
  • 【Mechanical Feeling & Fast Tapping】The PC Keyboard Keys are Designed for Mechanical Feeling, Giving You a Better Feel During Use and the Ability to Trigger Keys Quickly, Allowing You to Win All Your Games
  • 【19 Keys Anti-Ghosting Keyboard】Anti-Ghosting Ensures Every Button Can Be Triggered. This Allows You to Trigger Key Combinations In The Game Accurately, And Each Skill Can Be Accurately Released to Increase Your Winning Rate. Redragon K521 Will Be Your Perfect Partner
  • 【12 Multimedia Combination Keys】The K521 Wired Gaming Keyboard is Equipped with 12 Multimedia Keys That Can Greatly Enhance Your Gaming/Office Efficiency and Make It More Convenient to Use

Do not replace the event with a fixed sleep

The Page API says: “Never wait for timeout in production. Tests that wait for time are inherently flaky.” page.waitForTimeout() is suitable for debugging a timing hypothesis, not for synchronizing a production test. Replace it with the event, selector, assertion, or load condition that represents the behavior under test.

Common symptoms and fixes

Symptom Likely cause Fix
The wait hangs immediately after a click Listener was registered after a fast event Create the promise before the click
Raw event arrives but filtered wait times out Predicate never returns truthy Log the payload and correct URL, status, or filename assumptions
Popup wait times out, but a new tab appears Listening on the wrong page Use the page that opened it, or listen on the context
Wait fails during teardown Page or context closed first Move cleanup after the awaited event and readiness assertion
Popup event resolves, then element lookup fails Event arrival was confused with content readiness Wait for domcontentloaded or the required web assertion
Increasing timeout changes nothing Missing event, wrong scope, or impossible predicate Return to ordering, identity, scope, and payload checks
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 the task is simply to obtain a clean screenshot or PDF rather than test an event-driven browser flow, ScreenshotNeo provides a single HTTP request. Its API accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be disabled. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers report the page verdict and billing status. It also offers an MCP server with take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients.

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

See the parameter reference in the ScreenshotNeo documentation. cURL:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Python:

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)

Node.js:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

Every feature is included on every plan: the Free plan provides 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account to try the API without a card.

FAQ

Does waitForEvent wait for network requests to finish?

No. It resolves when the specified event is emitted and, if supplied, accepted by its predicate. Use a separate assertion or readiness wait for the result your test needs.

Can I use one promise for multiple possible events?

Use separate waits or a deliberately designed abstraction that handles each event type. A predicate on one event cannot turn it into a listener for a different event.

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

What should I check when the event is emitted by application code?

Confirm the browser action reaches that code path and that the event is emitted on the same page or context object your test is observing. Instrument the application or inspect Playwright tracing rather than adding a longer sleep.

Best Value
Sale
Logitech K270 Full Size Wireless Keyboard for Windows - Black
  • All-day Comfort: This USB keyboard creates a comfortable and familiar typing experience thanks to the deep-profile keys and standard full-size layout with all F-keys, number pad and arrow keys
  • Built to Last: The spill-proof (2) design and durable print characters keep you on track for years to come despite any on-the-job mishaps; it’s a reliable partner for your desk at home, or at work
  • Long-lasting Battery Life: A 24-month battery life (4) means you can go for 2 years without the hassle of changing batteries of your wireless full-size keyboard
  • Simply plug the USB receiver into a USB port on your desktop, laptop or netbook computer and start using the keyboard right away without any software installation
  • Simply Wireless: Forget about drop-outs and delays thanks to a strong, reliable wireless connection with up to 33 ft range (5); K270 is compatible with Windows 7, 8, 10 or later

Are these examples identical in Python, Java, and .NET?

No. The examples use JavaScript/TypeScript syntax. Consult the API documentation for the binding and Playwright version installed in your project before translating option names or timeout behavior.

Frequently Asked Questions

Does waitForEvent wait for network requests to finish?

No. It resolves when the specified event is emitted and, if supplied, accepted by its predicate. Use a separate assertion or readiness wait for the result your test needs.

Can I use one promise for multiple possible events?

Use separate waits or a deliberately designed abstraction that handles each event type. A predicate on one event cannot turn it into a listener for a different event.

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

What should I check when the event is emitted by application code?

Confirm the browser action reaches that code path and that the event is emitted on the same page or context object your test is observing. Instrument the application or inspect Playwright tracing rather than adding a longer sleep.

Are these examples identical in Python, Java, and .NET?

No. The examples use JavaScript/TypeScript syntax. Consult the API documentation for the binding and Playwright version installed in your project before translating option names or timeout behavior.

Quick Recap

Bestseller No. 1
SaleBestseller No. 3
Logitech K120 Full Size Wired Keyboard USB Plug-and-Play Windows - Black
Logitech K120 Full Size Wired Keyboard USB Plug-and-Play Windows - Black
Plastic parts in K120 include 51% certified post-consumer recycled plastic*; Product carbon footprint: 4.02 kg CO2e
$12.34
SaleBestseller No. 5
Logitech K270 Full Size Wireless Keyboard for Windows - Black
Logitech K270 Full Size Wireless Keyboard for Windows - Black
Plastic parts in K270 include 38% certified post-consumer recycled plastic; Eight hot keys: For instant access to the Internet, e-mail, music volume and more
$21.48

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.