{"record":{"id":"c14a165fc36bea8e","repo":"grafana/k6","slug":"parsing-waitforloadstate-q-options-w","errorCode":null,"errorMessage":"parsing waitForLoadState %q options: %w","messagePattern":"parsing waitForLoadState %q options: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/browser/frame_mapping.go","lineNumber":446,"sourceCode":"\t\t\t}), nil\n\t\t},\n\t\t\"url\": f.URL,\n\t\t\"waitForFunction\": func(pageFunc, opts sobek.Value, args ...sobek.Value) (*sobek.Promise, error) {\n\t\t\tjs, popts, pargs, err := parseWaitForFunctionArgs(\n\t\t\t\trt, f.Timeout(), pageFunc, opts, args...,\n\t\t\t)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"frame waitForFunction: %w\", err)\n\t\t\t}\n\n\t\t\treturn promise(vu, func() (result any, reason error) {\n\t\t\t\treturn f.WaitForFunction(js, popts, pargs...) //nolint:wrapcheck\n\t\t\t}), nil\n\t\t},\n\t\t\"waitForLoadState\": func(state string, opts sobek.Value) (*sobek.Promise, error) {\n\t\t\tpopts, err := parseFrameWaitForLoadStateOptions(rt, opts, f.Timeout())\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parsing waitForLoadState %q options: %w\", state, err)\n\t\t\t}\n\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\treturn nil, f.WaitForLoadState(state, popts) //nolint:wrapcheck\n\t\t\t}), nil\n\t\t},\n\t\t\"waitForNavigation\": func(opts sobek.Value) (*sobek.Promise, error) {\n\t\t\treturn mapWaitForNavigation(rt, vu, f, opts)\n\t\t},\n\t\t\"waitForSelector\": func(selector string, opts sobek.Value) (*sobek.Promise, error) {\n\t\t\tpopts, err := parseFrameWaitForSelectorOptions(rt, opts, f.Timeout())\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parsing wait for selector %q options: %w\", selector, err)\n\t\t\t}\n\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\teh, err := f.WaitForSelector(selector, popts)\n\t\t\t\tif err != nil {","sourceCodeStart":428,"sourceCodeEnd":464,"githubUrl":"https://github.com/grafana/k6/blob/8d06114777191d21ef885d05c5f8aa9e1ed838ae/internal/js/modules/k6/browser/browser/frame_mapping.go#L428-L464","documentation":"Thrown while parsing the options object of frame.waitForLoadState(state, options) (browser/frame_mapping.go:448); the requested state is echoed via %q. FrameWaitForLoadStateOptions.Parse reads only timeout (coercively) and cannot fail in current k6, so the wrap is defensive. An invalid state string such as 'networkIdle' fails separately inside WaitForLoadState with a lifecycle-event error, not here.","triggerScenarios":"Exotic options values (Symbol, throwing getters) that sobek cannot traverse; older k6 builds with stricter option export; passing the state in the options object instead of as the first argument is silently ignored, which often precedes a state error elsewhere.","commonSituations":"Casing mistakes copied from other tools ('networkIdle' vs the supported 'load', 'domcontentloaded', 'networkidle'); options built from parsed JSON; k6 version drift in parser strictness.","solutions":["Keep options to a plain { timeout: <number> } object","Pass the state as the first argument, lowercase: 'load' | 'domcontentloaded' | 'networkidle'","Omit options to use the frame default timeout","Upgrade k6 if you hit this with an ordinary options object"],"exampleFix":"// before\nframe.waitForLoadState('networkIdle', { timeout: '5000' });\n// after\nframe.waitForLoadState('networkidle', { timeout: 5000 });","handlingStrategy":"validation","validationCode":"const STATES = ['load', 'domcontentloaded', 'networkidle'];\nif (!STATES.includes(state)) throw new Error(`state must be one of ${STATES.join('|')}`);\nconst o = { ...(opts?.timeout !== undefined && { timeout: Number(opts.timeout) }) };","typeGuard":"function isWaitForLoadStateArgs(state, o) {\n  return ['load', 'domcontentloaded', 'networkidle'].includes(state) &&\n    (o == null || typeof o === 'object' && (o.timeout === undefined || typeof o.timeout === 'number'));\n}","tryCatchPattern":"try { await frame.waitForLoadState(state, o); } catch (e) { if (!String(e.message).includes('waitForLoadState')) throw e; }","preventionTips":["State strings are lowercase; watch for 'networkIdle' casing copied from other tools","Pass state as the first argument, not inside options","Trim/lowercase state values that come from data files"],"tags":["k6","k6-browser","frame","wait-for-load-state","lifecycle","options"],"backgroundTag":"options-validation-failed","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"}