grafana/k6 · error
waiting for page event
Error message
waiting for page event %q: %w
What it means
Thrown when the underlying p.WaitForEvent call fails after the options parsed and the wait started. It wraps the raw failure: most commonly a timeout waiting for the event within p.Timeout() (the page/action timeout), but also browser or context closing mid-wait, or an error escaping the predicate.
Solutions
- Increase the timeout: pass { timeout: 60000 } or raise the default with page.setDefaultTimeout(60000) / newContext({ actionTimeout }).
- Verify the triggering action actually happens (the click/navigation that should produce the event) and that the event name matches a mapped event.
- If using a predicate, confirm it can return true (test it against a captured event).
- Catch the rejection and fail the iteration with a descriptive k6 check message instead of an unhandled promise rejection.
Example fix
// before
const res = await page.waitForEvent('response');
// after
try {
const res = await page.waitForEvent('response', { timeout: 60000 });
} catch (e) {
check(null, { 'response event received': () => false });
throw e;
} Defensive patterns
Strategy: try-catch
Try / catch
try {
const ev = await page.waitForEvent('response', { timeout: 60000 });
} catch (e) {
if (/waiting for page event/.test(e.message)) {
check(null, { 'event arrived in time': () => false });
}
throw e;
} Prevention
- Set realistic timeouts (page.setDefaultTimeout / newContext actionTimeout) instead of relying on the 30s default under load.
- Confirm the action that should trigger the event succeeded before waiting for it.
- Verify predicates can return true by logging captured events once.
When it happens
Trigger: page.waitForEvent('response', { timeout: 1000 }) when no matching network exchange happens in time; the page navigating away or being closed before the event fires; a predicate that never returns true; running against a slow site under load where responses exceed the default 30s action timeout.
Common situations: Waiting for events that never occur because the selector/navigation step before them failed silently; tight timeouts in CI; heavy pages under k6 load where responses are slower than scripted; browser context closed by script end while an event wait is in flight.
Related errors
- executing waitForEvent predicate
- parsing waitForEvent options
- waitForEvent does not support mapping for event
- an error occurred communicating with k6 Cloud
- " " attribute is only supported for roles: "`).join(", ")}
AI-assisted analysis of grafana/k6@8d06114777 (2026-08-18).
Data as JSON: /api/errors/3d100b5131f641c5.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/browser/browser/page_mapping.go:722
return promise(vu, func() (any, error) {
rpe, err := p.WaitForEvent(event, popts, func(pe common.PageEvent) (bool, error) {
if fn == nil {
return true, nil
}
return queueTask(ctx, tq, func() (bool, error) {
m, err := mapPageEvent(vu, pe)
if err != nil {
return false, err
}
v, err := fn(sobek.Undefined(), vu.Runtime().ToValue(m))
if err != nil {
return false, fmt.Errorf("executing waitForEvent predicate: %w", err)
}
return v.ToBoolean(), nil
})()
})
if err != nil {
return nil, fmt.Errorf("waiting for page event %q: %w", event, err)
}
return mapPageEvent(vu, rpe)
}), nil
},
"workers": func() *sobek.Object {
workers := p.Workers()
mws := make([]mapping, 0, len(workers))
for _, w := range workers {
mw := mapWorker(vu, w)
mws = append(mws, mw)
}
return rt.ToValue(mws).ToObject(rt)
},
}
maps["$"] = func(selector string) *sobek.Promise {
return promise(vu, func() (any, error) {
eh, err := p.Query(selector)
if err != nil {View on GitHub (pinned to 8d06114777)