grafana/k6 · error
parsing waitForResponse options
Error message
parsing waitForResponse options: %w
What it means
Thrown by page.waitForResponse(url, opts) in the k6 browser module when the opts argument cannot be parsed. The parser (parsePageWaitForResponseOptions) accepts exactly one key, 'timeout' (milliseconds); any other property is rejected, and the failure is wrapped in this message before the promise is even created.
Solutions
- Reduce the options object to only { timeout: <milliseconds> }, or omit the second argument entirely to use the page default timeout.
- If you passed 'polling' or a predicate, move that logic: polling belongs to waitForFunction, filtering belongs in the URL pattern or a waitForEvent predicate.
- Check for typos in the key name (e.g. 'timeouts' vs 'timeout').
- Set a global default with browser.newContext({ actionTimeout: ... }) or page.setDefaultTimeout instead of per-call options.
Example fix
// before
const res = await page.waitForResponse('**/api/users', { polling: 100 });
// after
const res = await page.waitForResponse('**/api/users', { timeout: 30000 }); Defensive patterns
Strategy: validation
Validate before calling
function safeWaitForResponseOpts(opts) {
if (opts == null) return undefined;
const out = {};
for (const k of Object.keys(opts)) {
if (k !== 'timeout') throw new Error(`waitForResponse does not support option '${k}'`);
out.timeout = Number(opts.timeout);
}
return out;
}
const res = await page.waitForResponse('**/api', safeWaitForResponseOpts({ timeout: 5000 })); Type guard
const isWaitForResponseOpts = (o) => o == null || (typeof o === 'object' && Object.keys(o).every(k => k === 'timeout') && (o.timeout === undefined || typeof o.timeout === 'number'));
Try / catch
try { await page.waitForResponse(url, opts); } catch (e) { if (e.message.includes('parsing waitForResponse options')) throw new Error(`Bad waitForResponse options: ${e.message}`); throw e; } Prevention
- Keep a per-API options object instead of one shared literal across waitFor* calls.
- Set the default action timeout once via newContext({ actionTimeout }) to avoid per-call options.
- Grep scripts in CI for known-invalid keys (polling, predicate) inside waitForResponse calls.
When it happens
Trigger: Calling page.waitForResponse('**/api/data', { polling: 100 }), or with any opts key other than 'timeout' (e.g. {timeoutMs: 5000}, {predicate: fn}). Passing a non-object second argument that is not null/undefined (e.g. a number or string) also fails when ToObject/Keys iteration surfaces unexpected keys.
Common situations: Porting Playwright scripts where waitForResponse was given option objects from other APIs; copy-pasting waitForFunction-style options (polling) into waitForResponse; typos in the timeout key; assuming options accepted by context.waitForResponse differ from page.waitForResponse.
Related errors
- parsing frame wait for navigation options
- parsing waitForEvent options
- parsing waitForFunction options
- parsing waitForRequest options
- parsing waitForURL options
AI-assisted analysis of grafana/k6@8d06114777 (2026-08-18).
Data as JSON: /api/errors/89826d525e90156e.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/browser/browser/page_mapping.go:634
if err != nil {
return nil, err //nolint:wrapcheck
}
return mapElementHandle(vu, eh), nil
}), nil
},
"waitForTimeout": func(timeout int64) *sobek.Promise {
return promise(vu, func() (any, error) {
p.WaitForTimeout(timeout)
return nil, nil
})
},
"waitForURL": func(url sobek.Value, opts sobek.Value) (*sobek.Promise, error) {
return mapWaitForURL(rt, vu, p, url, opts)
},
"waitForResponse": func(url sobek.Value, opts sobek.Value) (*sobek.Promise, error) {
popts, err := parsePageWaitForResponseOptions(vu.Context(), opts, p.Timeout())
if err != nil {
return nil, fmt.Errorf("parsing waitForResponse options: %w", err)
}
var val string
switch url.ExportType() {
case reflect.TypeFor[string]():
val = "'" + url.String() + "'" // Strings require quotes
default: // JS Regex, CSS, numbers or booleans
val = url.String() // No quotes
}
tq, ctx, stop := newTaskQueue(vu)
return promise(vu, func() (result any, reason error) {
defer stop()
return p.WaitForResponse(val, popts, newRegExMatcher(ctx, vu, tq))
}), nil
},
"waitForRequest": func(url sobek.Value, opts sobek.Value) (*sobek.Promise, error) {View on GitHub (pinned to 8d06114777)