{"record":{"id":"aa5f565ed380147c","repo":"grafana/k6","slug":"parsing-waitforelementstate-options-w","errorCode":null,"errorMessage":"parsing waitForElementState options: %w","messagePattern":"parsing waitForElementState options: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/browser/element_handle_mapping.go","lineNumber":292,"sourceCode":"\t\t\t\treturn nil, fmt.Errorf(\"parsing type options: %w\", err)\n\t\t\t}\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\treturn nil, eh.Type(text, popts) //nolint:wrapcheck\n\t\t\t}), nil\n\t\t},\n\t\t\"uncheck\": func(opts sobek.Value) (*sobek.Promise, error) {\n\t\t\tpopts, err := parseElementHandleSetCheckedOptions(rt, opts, eh.DefaultTimeout())\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parsing uncheck options: %w\", err)\n\t\t\t}\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\treturn nil, eh.Uncheck(popts) //nolint:wrapcheck\n\t\t\t}), nil\n\t\t},\n\t\t\"waitForElementState\": func(state string, opts sobek.Value) (*sobek.Promise, error) {\n\t\t\tpopts, err := parseElementHandleWaitForElementStateOptions(rt, opts, eh.DefaultTimeout())\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parsing waitForElementState options: %w\", err)\n\t\t\t}\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\treturn nil, eh.WaitForElementState(state, popts) //nolint:wrapcheck\n\t\t\t}), nil\n\t\t},\n\t\t\"waitForSelector\": func(selector string, opts sobek.Value) (*sobek.Promise, error) {\n\t\t\tpopts, err := parseFrameWaitForSelectorOptions(rt, opts, eh.DefaultTimeout())\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parsing waitForSelector %q options: %w\", selector, err)\n\t\t\t}\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\teh, err := eh.WaitForSelector(selector, popts)\n\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},","sourceCodeStart":274,"sourceCodeEnd":310,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/browser/element_handle_mapping.go#L274-L310","documentation":"Thrown when ElementHandle.waitForElementState cannot parse its options. ElementHandleWaitForElementStateOptions.Parse reads only the timeout key, coerces it with ToInteger, and ignores unknown keys, so this error wrap has no realistic trigger in the current code. An invalid state string is validated later inside WaitForElementState and produces a different error.","triggerScenarios":"Calling waitForElementState('visible', opts) with an opts value that cannot be converted to an object (e.g. a Symbol) — ordinary objects, numbers-in-strings, null and undefined all coerce fine.","commonSituations":"Practically never occurs; note that passing a bad state like 'enabled' fails elsewhere with a state-validation message, which users often mistake for this parse error.","solutions":["Pass options as a plain object with a numeric timeout, or omit them","If you meant to fix an invalid-state failure, use one of attached|detached|visible|hidden in the first argument","Inspect the wrapped error after the colon for the true cause"],"exampleFix":"// before\nawait handle.waitForElementState('visible', '3000');\n// after\nawait handle.waitForElementState('visible', { timeout: 3000 });","handlingStrategy":"try-catch","validationCode":"const states = ['attached', 'detached', 'visible', 'hidden'];\nif (!states.includes(state)) throw new Error(`state must be one of ${states.join('|')}`);\nawait handle.waitForElementState(state, { timeout: Number(timeoutMs) });","typeGuard":null,"tryCatchPattern":"try {\n  await handle.waitForElementState(state, opts);\n} catch (e) {\n  if (String(e).includes('parsing waitForElementState options')) {\n    await handle.waitForElementState(state); // retry with defaults\n  } else { throw e; }\n}","preventionTips":["Restrict state to attached|detached|visible|hidden — validated later, but worth pre-checking","Keep timeout numeric","Don't confuse this parse error with the separate invalid-state error"],"tags":["k6","browser","element-handle","waitforelementstate","options"],"backgroundTag":"options-validation-failed","analyzedSha":"3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee","analyzedAt":"2026-09-14T20:10:14.619Z","contentChangedAt":"2026-09-14T20:10:14.619Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}