{
  "slug": "k6-browser-page-waitforevent-synchronizes-on-events-a05900ed5e02",
  "title": "k6/browser page.waitForEvent() synchronizes on events",
  "tools": [
    "k6"
  ],
  "tags": [
    "agent"
  ],
  "introduced_at": "2026-01-05T19:37:51.000Z",
  "announced_at": "2026-01-05T19:37:51.000Z",
  "effective_at": null,
  "date_basis": "source-publication",
  "status": "unknown",
  "how": {
    "incantation": "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.",
    "examples": [
      "const msgPromise = page.waitForEvent('console', msg => msg.text().includes('hello'));\nawait page.evaluate(() => console.log('hello world'));\nconst msg = await msgPromise;",
      "const resPromise = page.waitForEvent('response', {\n  predicate: res => res.url().includes('/api/data'),\n  timeout: 5000,\n});\nawait page.click('button#fetch-data');\nconst res = await resPromise;"
    ],
    "gotchas": [
      "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."
    ]
  },
  "why_it_matters": "Write a browser test that proceeds after a specific console message or matching response is observed.",
  "sources": [
    "https://github.com/grafana/k6/releases/tag/v1.5.0",
    "https://github.com/grafana/k6/blob/v1.5.0/release%20notes/v1.5.0.md",
    "https://grafana.com/docs/k6/latest/javascript-api/k6-browser/page/waitforevent/"
  ],
  "rank": 0.99061,
  "judge": {
    "publish": true,
    "judge_model": "codex-cli/gpt-6-luna+typesafe/jev-1.13.0",
    "prompt_version": "extract-v7+enrich-v2+judge-v2x3+jev-publish-v1"
  },
  "review_state": "approved",
  "provenance": {
    "run_id": "wave2a-20261017",
    "verdict_id": "wave2a-20261017:wave2a-20261017-586cf8a8904fff8d-1:gate",
    "evidence_hash": "a56e3f88b056059d85ecbdf65359def0fbd1d2054d8cb41abb9141ea3143a06c"
  },
  "review": {
    "draft_hash": "00ef56ba753efec4030bd8691d2df658f150cb2b01aa349c01275b190e3ce992",
    "reviewer": "publication-gate",
    "reviewed_at": "2026-10-07T00:00:00.000Z",
    "decision": "wave2a-20261017:gate",
    "reason": "3 of 3 judge runs approved with p_yes >= 0.9 (mean 0.99 >= 0.9; 2 needed) and Jev gave 0.80 (>= 0.6 needed)."
  }
}
