sincecutoff.com
← all changes

k6/browser page.waitForEvent() synchronizes on events

Introduced 2026-01-05 · score 0.99

HOW TO USE IT

When a browser test must wait for a console, request, or response event, call `page.waitForEvent(event[, optionsOrPredicate])` before triggering the event and await its promise before continuing.

const msgPromise = page.waitForEvent('console', msg => msg.text().includes('hello')); await page.evaluate(() => console.log('hello world')); const msg = await msgPromise;
const resPromise = page.waitForEvent('response', { predicate: res => res.url().includes('/api/data'), timeout: 5000, }); await page.click('button#fetch-data'); const res = await resPromise;

WHY THIS HELPS

Write a browser test that proceeds after a specific console message or matching response is observed.

REQUIREMENTS AND LIMITATIONS

  • Version: v1.5.0
  • event (required): Event name; supported values are `console`, `request`, and `response.
  • optionsOrPredicate: A predicate function or options object; the two forms are alternatives.
  • options.predicate: Function receiving the event object; return true when it is the expected event.
  • options.timeout: Maximum wait in milliseconds; default 30000, or 0 to disable. BrowserContext or Page `setDefaultTimeout` can override the default.
  • The method blocks the caller until the specified event is captured; with a predicate, it waits for an event satisfying that predicate.

FIRST-PARTY EVIDENCE

Check the installed version and the source before using it. Entry JSON

Report a problem with this card