grafana/k6 · error
parsing wait for event options
Error message
parsing wait for event options: %w
What it means
Generic parse wrapper in browserContext.waitForEvent: parseWaitForEventOptions failed to interpret the optsOrPredicate argument. It must be either a predicate function or an options object containing only 'predicate' (callable) and/or 'timeout' (milliseconds) keys.
Solutions
- Pass a function: waitForEvent('popup', p => p.url().includes('example'))
- Or pass an options object with only 'predicate' and/or 'timeout' keys: waitForEvent('popup', { timeout: 5000, predicate: fn })
- Ensure the predicate is an actual function
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at internal/js/modules/k6/browser/browser/browser_context_mapping.go:123 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18).
Data as JSON: /api/errors/931cd34fbf881cfe.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/browser/browser/browser_context_mapping.go:123
if err != nil {
return nil, fmt.Errorf("parsing HTTP credentials: %w", err)
}
return promise(vu, func() (any, error) {
return nil, bc.SetHTTPCredentials(creds) //nolint:staticcheck
}), nil
},
"setOffline": func(offline bool) *sobek.Promise {
return promise(vu, func() (any, error) {
return nil, bc.SetOffline(offline) //nolint:wrapcheck
})
},
"waitForEvent": func(event string, optsOrPredicate sobek.Value) (*sobek.Promise, error) {
rt := vu.Runtime()
ctx := vu.Context()
popts, err := parseWaitForEventOptions(rt, optsOrPredicate, bc.Timeout())
if err != nil {
return nil, fmt.Errorf("parsing wait for event options: %w", err)
}
// Waits until the first event if no predicate is specified.
var pred func(p *common.Page) (bool, error)
// Waits until the event that satisfies the predicate.
if popts.PredicateFn != nil {
pred = func(p *common.Page) (bool, error) {
return queueTask(ctx, vu.get(ctx, p.TargetID()), func() (bool, error) {
v, err := popts.PredicateFn(rt.ToValue(p))
if err != nil {
return false, err
}
return v.ToBoolean(), nil
})()
}
}
View on GitHub (pinned to 01ffac6f24)