{"record":{"id":"89c50e5e518ed324","repo":"grafana/k6","slug":"parsing-waitforrequest-options-w","errorCode":null,"errorMessage":"parsing waitForRequest options: %w","messagePattern":"parsing waitForRequest options: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/browser/page_mapping.go","lineNumber":655,"sourceCode":"\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) {\n\t\t\tpopts, err := parsePageWaitForRequestOptions(vu.Context(), opts, p.Timeout())\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parsing waitForRequest 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.WaitForRequest(val, popts, newRegExMatcher(ctx, vu, tq))\n\t\t\t}), nil\n\t\t},\n\t\t\"waitForEvent\": func(event common.PageEventName, opts sobek.Value) (*sobek.Promise, error) {","sourceCodeStart":637,"sourceCodeEnd":673,"githubUrl":"https://github.com/grafana/k6/blob/8d06114777191d21ef885d05c5f8aa9e1ed838ae/internal/js/modules/k6/browser/browser/page_mapping.go#L637-L673","documentation":"Thrown by page.waitForRequest(url, opts) in the k6 browser module when the opts argument cannot be parsed. parsePageWaitForRequestOptions only recognizes the 'timeout' key (integer milliseconds); any other key in the object is rejected and wrapped in this error.","triggerScenarios":"Calling page.waitForRequest('/api/login', { headers: {...} }), or any second argument object containing keys besides 'timeout'. Passing options designed for http.post (headers, auth) instead of the wait API also triggers it.","commonSituations":"Assuming waitForRequest accepts request-shaping options (headers, method) like Playwright's page.waitForRequest(urlOrPredicate, options) does not; copying options from waitForFunction or waitForLoadState; typos such as {timeoutms: 5000}.","solutions":["Use only { timeout: <milliseconds> } as the second argument, or omit it to inherit page.setTimeout()/default timeout.","To match more than a URL, pass a RegExp as the first argument instead of adding option keys.","Remove Playwright-only keys (headers, method, predicate) from the options object.","Configure the default action timeout once via browser.newContext({ actionTimeout }) so per-call options are unnecessary."],"exampleFix":"// before\nconst req = await page.waitForRequest('**/submit', { method: 'POST', timeout: 5000 });\n\n// after\nconst req = await page.waitForRequest('**/submit', { timeout: 5000 });","handlingStrategy":"validation","validationCode":"const opts = { timeout: 5000 };\nconst unknown = Object.keys(opts).filter(k => k !== 'timeout');\nif (unknown.length) throw new Error(`unsupported waitForRequest keys: ${unknown.join(', ')}`);\nawait page.waitForRequest('**/login', opts);","typeGuard":"const isWaitForRequestOpts = (o) => o == null || (typeof o === 'object' && Object.keys(o).every(k => k === 'timeout'));","tryCatchPattern":"try { await page.waitForRequest(url, opts); } catch (e) { if (e.message.includes('parsing waitForRequest options')) { /* fix opts and retry once */ } throw e; }","preventionTips":["Encode request filtering in the URL/RegExp pattern, never in options keys.","Use numeric millisecond timeouts only.","Port Playwright scripts with a mapping checklist of which options each k6 waitFor* API accepts."],"tags":["k6","browser","page","waitforrequest","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"}