{"record":{"id":"bfe969e0c680cb8d","repo":"grafana/k6","slug":"parsing-wait-for-options-w","errorCode":null,"errorMessage":"parsing wait for options: %w","messagePattern":"parsing wait for options: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/browser/locator_mapping.go","lineNumber":428,"sourceCode":"\t\t\t\treturn nil, fmt.Errorf(\"parsing locator tap options: %w\", err)\n\t\t\t}\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\treturn nil, lo.Tap(copts) //nolint:wrapcheck\n\t\t\t}), nil\n\t\t},\n\t\t\"dispatchEvent\": func(typ string, eventInit, opts sobek.Value) (*sobek.Promise, error) {\n\t\t\tpopts, err := parseFrameDispatchEventOptions(rt, opts, lo.DefaultTimeout())\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parsing locator dispatch event options: %w\", err)\n\t\t\t}\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\treturn nil, lo.DispatchEvent(typ, exportArg(eventInit), popts) //nolint:wrapcheck\n\t\t\t}), nil\n\t\t},\n\t\t\"waitFor\": func(opts sobek.Value) (*sobek.Promise, error) {\n\t\t\tcopts, err := parseFrameWaitForSelectorOptions(rt, opts, lo.Timeout())\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parsing wait for options: %w\", err)\n\t\t\t}\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\treturn nil, lo.WaitFor(copts) //nolint:wrapcheck\n\t\t\t}), nil\n\t\t},\n\t}\n}\n\nfunc parseLocatorOptions(rt *sobek.Runtime, opts sobek.Value) *common.LocatorOptions {\n\tif k6common.IsNullish(opts) {\n\t\treturn nil\n\t}\n\n\tvar popts common.LocatorOptions\n\n\tobj := opts.ToObject(rt)\n\tfor _, k := range obj.Keys() {\n\t\tswitch k {","sourceCodeStart":410,"sourceCodeEnd":446,"githubUrl":"https://github.com/grafana/k6/blob/8d06114777191d21ef885d05c5f8aa9e1ed838ae/internal/js/modules/k6/browser/browser/locator_mapping.go#L410-L446","documentation":"Thrown by k6 browser's Locator.waitFor(options) when the options object fails FrameWaitForSelectorOptions.Parse. The dominant cause is an invalid 'state' value: the parser only accepts 'attached', 'detached', 'visible', or 'hidden' (common/frame_options.go:754-760) and returns `\"<value>\" is not a valid DOM state` for anything else, which this message wraps. 'timeout' and 'strict' are the other recognized keys.","triggerScenarios":"Calling locator.waitFor({ state: 'enabled' }) or { state: 'disabled' } — states Playwright's waitForSelector never supported but often assumed; also 'stable', 'visible ' (trailing whitespace), or any typo like 'visable'. A non-object options value (BigInt, Symbol) that fails ToObject also lands here.","commonSituations":"Porting waitFor logic from Puppeteer (waitForSelector with different state vocabulary) or copying assertions code that uses elementHandle.isEnabled patterns; mismatches between Playwright docs examples and the subset k6 validates.","solutions":["Use one of the four valid states: locator.waitFor({ state: 'attached' | 'detached' | 'visible' | 'hidden' }).","For enabled/disabled semantics, wait for the element then assert with locator.isEnabled() or waitFor({state:'visible'}) plus your own check.","Verify the state string exactly (no quotes mismatch, no whitespace) when building options dynamically.","Call with no argument to use the default state 'visible' with the default timeout."],"exampleFix":"// before\nlocator.waitFor({ state: 'enabled', timeout: 5000 });\n\n// after\nawait locator.waitFor({ state: 'visible', timeout: 5000 });\nif (!(await locator.isEnabled())) throw new Error('element not enabled');","handlingStrategy":"validation","validationCode":"const VALID_STATES = new Set(['attached', 'detached', 'visible', 'hidden']);\nfunction waitForOpts(state, timeout) {\n  if (state && !VALID_STATES.has(state)) throw new Error(`invalid waitFor state: ${state}`);\n  return state ? { state, timeout } : { timeout };\n}\nawait locator.waitFor(waitForOpts(cfg.state, 5000));","typeGuard":"function isWaitForState(s) {\n  return s == null || ['attached', 'detached', 'visible', 'hidden'].includes(s);\n}","tryCatchPattern":"try { await locator.waitFor(opts); } catch (e) { if (/is not a valid DOM state|parsing wait for options/.test(e.message)) { /* log the state value and correct it */ } throw e; }","preventionTips":["Whitelist waitFor states to attached/detached/visible/hidden in a shared helper.","Do not port 'enabled'/'disabled' state waits from other tools; assert with isEnabled() after waiting for visible.","Centralize option building so a single validation point covers all waitFor calls."],"tags":["k6","browser","locator","wait-for","state-validation"],"backgroundTag":"invalid-options-argument","analyzedSha":"8d06114777191d21ef885d05c5f8aa9e1ed838ae","analyzedAt":"2026-09-14T20:10:14.619Z","contentChangedAt":"2026-09-14T20:10:14.619Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}