{"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":285,"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 := common.NewElementHandleSetCheckedOptions(eh.DefaultTimeout())\n\t\t\tif err := popts.Parse(vu.Context(), opts); 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 := common.NewElementHandleWaitForElementStateOptions(eh.DefaultTimeout())\n\t\t\tif err := popts.Parse(vu.Context(), opts); 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 := common.NewFrameWaitForSelectorOptions(eh.DefaultTimeout())\n\t\t\tif err := popts.Parse(vu.Context(), opts); 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":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/browser/element_handle_mapping.go#L267-L303","documentation":"Thrown synchronously by ElementHandle.waitForElementState() when its options fail to parse. ElementHandleWaitForElementStateOptions contains only timeout, parsed with a lenient coercion that always returns nil in common/element_handle_options.go, so this wrap is defensive and effectively unreachable in current k6. An invalid state string (first argument) is validated later inside the promise, not by this parse.","triggerScenarios":"In current code none: any timeout value coerces via ToInteger; unknown option keys are ignored. Older structural Parse builds could fail.","commonSituations":"Timeout passed as '10s' (coerced, leading to an unexpected wait duration); mistaking the in-promise error 'unexpected state: <state>' for an option-parse failure.","solutions":["Use { timeout: <ms number> } only","Use a valid state string: 'visible', 'hidden', 'stable', 'enabled', or 'disabled'","Upgrade k6 if this message appears; current Parse cannot fail","Check the wrapped cause after the colon to locate the failing field"],"exampleFix":"// before\nawait el.waitForElementState('visible', { timeout: '10s' });\n\n// after\nawait el.waitForElementState('visible', { timeout: 10000 });","handlingStrategy":"try-catch","validationCode":"const STATES = new Set(['visible', 'hidden', 'stable', 'enabled', 'disabled']);\nif (!STATES.has(state)) {\n  throw new Error(`waitForElementState(): invalid state '${state}'; use visible|hidden|stable|enabled|disabled`);\n}\nif (opts?.timeout !== undefined && !Number.isFinite(Number(opts.timeout))) {\n  throw new Error('waitForElementState(): timeout must be ms number');\n}","typeGuard":"function isWaitForElementStateOpts(o) {\n  if (o == null) return true;\n  return Object.keys(o).every(k => k === 'timeout') &&\n         (o.timeout === undefined || Number.isFinite(o.timeout));\n}","tryCatchPattern":"try {\n  await el.waitForElementState(state, opts);\n} catch (e) {\n  if (/parsing waitForElementState options/.test(String(e.message))) {\n    console.log(`fix options: ${e.message}`); // current k6 cannot raise this\n  } else if (/unexpected state/.test(String(e.message))) {\n    console.log(`invalid state argument: ${e.message}`); // validated inside the promise\n  } else throw e;\n}","preventionTips":["Validate the state argument against visible|hidden|stable|enabled|disabled before calling","timeout is the only supported option and must be milliseconds","Invalid state strings fail inside the promise, not at parse time: do not rely on this message for them"],"tags":["k6","browser","element-handle","wait-for-element-state","option-parsing"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}