{"record":{"id":"89826d525e90156e","repo":"grafana/k6","slug":"parsing-waitforresponse-options-w","errorCode":null,"errorMessage":"parsing waitForResponse options: %w","messagePattern":"parsing waitForResponse options: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/browser/page_mapping.go","lineNumber":634,"sourceCode":"\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, err //nolint:wrapcheck\n\t\t\t\t}\n\t\t\t\treturn mapElementHandle(vu, eh), nil\n\t\t\t}), nil\n\t\t},\n\t\t\"waitForTimeout\": func(timeout int64) *sobek.Promise {\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\tp.WaitForTimeout(timeout)\n\t\t\t\treturn nil, nil\n\t\t\t})\n\t\t},\n\t\t\"waitForURL\": func(url sobek.Value, opts sobek.Value) (*sobek.Promise, error) {\n\t\t\treturn mapWaitForURL(rt, vu, p, url, opts)\n\t\t},\n\t\t\"waitForResponse\": func(url sobek.Value, opts sobek.Value) (*sobek.Promise, error) {\n\t\t\tpopts, err := parsePageWaitForResponseOptions(vu.Context(), opts, p.Timeout())\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parsing waitForResponse options: %w\", err)\n\t\t\t}\n\n\t\t\tvar val string\n\t\t\tswitch url.ExportType() {\n\t\t\tcase reflect.TypeFor[string]():\n\t\t\t\tval = \"'\" + url.String() + \"'\" // Strings require quotes\n\t\t\tdefault: // JS Regex, CSS, numbers or booleans\n\t\t\t\tval = url.String() // No quotes\n\t\t\t}\n\n\t\t\ttq, ctx, stop := newTaskQueue(vu)\n\n\t\t\treturn promise(vu, func() (result any, reason error) {\n\t\t\t\tdefer stop()\n\t\t\t\treturn p.WaitForResponse(val, popts, newRegExMatcher(ctx, vu, tq))\n\t\t\t}), nil\n\t\t},\n\t\t\"waitForRequest\": func(url sobek.Value, opts sobek.Value) (*sobek.Promise, error) {","sourceCodeStart":616,"sourceCodeEnd":652,"githubUrl":"https://github.com/grafana/k6/blob/8d06114777191d21ef885d05c5f8aa9e1ed838ae/internal/js/modules/k6/browser/browser/page_mapping.go#L616-L652","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nconst res = await page.waitForResponse('**/api/users', { polling: 100 });\n\n// after\nconst res = await page.waitForResponse('**/api/users', { timeout: 30000 });","handlingStrategy":"validation","validationCode":"function safeWaitForResponseOpts(opts) {\n  if (opts == null) return undefined;\n  const out = {};\n  for (const k of Object.keys(opts)) {\n    if (k !== 'timeout') throw new Error(`waitForResponse does not support option '${k}'`);\n    out.timeout = Number(opts.timeout);\n  }\n  return out;\n}\nconst res = await page.waitForResponse('**/api', safeWaitForResponseOpts({ timeout: 5000 }));","typeGuard":"const isWaitForResponseOpts = (o) => o == null || (typeof o === 'object' && Object.keys(o).every(k => k === 'timeout') && (o.timeout === undefined || typeof o.timeout === 'number'));","tryCatchPattern":"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; }","preventionTips":["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."],"tags":["k6","browser","page","waitforresponse","options","argument-validation"],"backgroundTag":"invalid-options-object","analyzedSha":"8d06114777191d21ef885d05c5f8aa9e1ed838ae","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}