{"record":{"id":"d49576fae232e5c3","repo":"grafana/k6","slug":"parsing-waitforevent-options-w","errorCode":null,"errorMessage":"parsing waitForEvent options: %w","messagePattern":"parsing waitForEvent options: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/browser/page_mapping.go","lineNumber":698,"sourceCode":"\t\t\t\tcase common.PageEventConsole:\n\t\t\t\t\treturn mapConsoleMessage(vu, pe), nil\n\t\t\t\tcase common.PageEventRequest:\n\t\t\t\t\treturn mapRequestEvent(vu, pe), nil\n\t\t\t\tcase common.PageEventResponse:\n\t\t\t\t\treturn mapResponseEvent(vu, pe), nil\n\t\t\t\tcase common.PageEventRequestFinished:\n\t\t\t\t\treturn mapRequestEvent(vu, pe), nil\n\t\t\t\tcase common.PageEventRequestFailed:\n\t\t\t\t\treturn mapRequestEvent(vu, pe), nil\n\t\t\t\tcase common.PageEventMetric:\n\t\t\t\t\t// intentionally left blank\n\t\t\t\t}\n\t\t\t\treturn nil, fmt.Errorf(\"waitForEvent does not support mapping for event: %q\", event)\n\t\t\t}\n\n\t\t\tpopts, fn, err := parsePageWaitForEventOptions(vu.Context(), opts, p.Timeout())\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parsing waitForEvent options: %w\", err)\n\t\t\t}\n\n\t\t\tctx := vu.Context()\n\t\t\ttq := vu.get(ctx, p.TargetID())\n\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\trpe, err := p.WaitForEvent(event, popts, func(pe common.PageEvent) (bool, error) {\n\t\t\t\t\tif fn == nil {\n\t\t\t\t\t\treturn true, nil\n\t\t\t\t\t}\n\t\t\t\t\treturn queueTask(ctx, tq, func() (bool, error) {\n\t\t\t\t\t\tm, err := mapPageEvent(vu, pe)\n\t\t\t\t\t\tif err != nil {\n\t\t\t\t\t\t\treturn false, err\n\t\t\t\t\t\t}\n\t\t\t\t\t\tv, err := fn(sobek.Undefined(), vu.Runtime().ToValue(m))\n\t\t\t\t\t\tif err != nil {\n\t\t\t\t\t\t\treturn false, fmt.Errorf(\"executing waitForEvent predicate: %w\", err)","sourceCodeStart":680,"sourceCodeEnd":716,"githubUrl":"https://github.com/grafana/k6/blob/8d06114777191d21ef885d05c5f8aa9e1ed838ae/internal/js/modules/k6/browser/browser/page_mapping.go#L680-L716","documentation":"Thrown by page.waitForEvent(eventName, opts) when parsePageWaitForEventOptions rejects the options object. The accepted keys are exactly 'timeout' (integer milliseconds) and 'predicate' (a function); unknown keys produce \"waitForEvent does not support option: '%s'\" and a non-callable predicate produces \"predicate must be a function\", both wrapped in this message.","triggerScenarios":"Calling page.waitForEvent('response', { timeout: 5000, url: '**/api' }) (unknown key 'url'); passing predicate as a string of source code or an object; passing a timeout value whose ToInteger conversion is unintended (e.g. '30s' becomes NaN/0 ms).","commonSituations":"Copy-pasting Playwright options that filter by URL or predicate syntax differences; passing an inline arrow wrapped in quotes; assuming string durations like '30s' are parsed (they are not — raw milliseconds are required).","solutions":["Restrict the options object to { timeout: <ms>, predicate: (event) => boolean }.","Move URL filtering into the predicate: { predicate: e => e.url().includes('/api') }.","Express timeouts as plain millisecond numbers, never strings.","Omit the second argument to use the page default timeout when no custom behavior is needed."],"exampleFix":"// before\nawait page.waitForEvent('response', { url: '**/api/users' });\n\n// after\nawait page.waitForEvent('response', { predicate: r => r.url().includes('/api/users') });","handlingStrategy":"validation","validationCode":"const opts = { timeout: 5000, predicate: e => true };\nconst badKeys = Object.keys(opts).filter(k => k !== 'timeout' && k !== 'predicate');\nif (badKeys.length || (opts.predicate !== undefined && typeof opts.predicate !== 'function')) {\n  throw new Error(`invalid waitForEvent options: ${badKeys.join(',') || 'predicate'}`);\n}\nawait page.waitForEvent('response', opts);","typeGuard":"const isWaitForEventOpts = (o) => o == null || (typeof o === 'object' && Object.keys(o).every(k => k === 'timeout' || k === 'predicate') && (o.predicate === undefined || typeof o.predicate === 'function'));","tryCatchPattern":"try { await page.waitForEvent(ev, opts); } catch (e) { if (e.message.includes('parsing waitForEvent options')) { /* strip bad keys and retry */ } throw e; }","preventionTips":["Encode URL/method filters inside the predicate, not as top-level option keys.","Use plain millisecond numbers for timeout.","Lift predicate definitions into named functions so a type error is caught at authoring time."],"tags":["k6","browser","page","waitforevent","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"}