{"record":{"id":"decb181330264db3","repo":"grafana/k6","slug":"q-is-not-a-valid-dom-state-frame-mapping","errorCode":null,"errorMessage":"%q is not a valid DOM state","messagePattern":"%q is not a valid DOM state","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/browser/frame_mapping.go","lineNumber":938,"sourceCode":"\n// parseFrameWaitForSelectorOptions parses the frame waitForSelector options from a Sobek value.\nfunc parseFrameWaitForSelectorOptions(\n\trt *sobek.Runtime, opts sobek.Value,\n\tdefaultTimeout time.Duration,\n) (*common.FrameWaitForSelectorOptions, error) {\n\twsopts := common.NewFrameWaitForSelectorOptions(defaultTimeout)\n\tif k6common.IsNullish(opts) {\n\t\treturn wsopts, nil\n\t}\n\tobj := opts.ToObject(rt)\n\tfor _, k := range obj.Keys() {\n\t\tswitch k {\n\t\tcase \"state\":\n\t\t\tstate := obj.Get(k).String()\n\t\t\tif s, ok := common.DOMElementStateIDFromString(state); ok {\n\t\t\t\twsopts.State = s\n\t\t\t} else {\n\t\t\t\treturn wsopts, fmt.Errorf(\"%q is not a valid DOM state\", state)\n\t\t\t}\n\t\tcase \"strict\":\n\t\t\twsopts.Strict = obj.Get(k).ToBoolean()\n\t\tcase \"timeout\":\n\t\t\twsopts.Timeout = time.Duration(obj.Get(k).ToInteger()) * time.Millisecond\n\t\t}\n\t}\n\treturn wsopts, nil\n}\n\n// parseFrameIsHiddenOptions parses the frame isHidden options from a Sobek value.\n//\n//nolint:unparam\nfunc parseFrameIsHiddenOptions(\n\trt *sobek.Runtime, opts sobek.Value,\n) (*common.FrameIsHiddenOptions, error) {\n\ttcopts := common.NewFrameIsHiddenOptions()\n\ttcopts.Strict = parseStrict(rt, opts)","sourceCodeStart":920,"sourceCodeEnd":956,"githubUrl":"https://github.com/grafana/k6/blob/8d06114777191d21ef885d05c5f8aa9e1ed838ae/internal/js/modules/k6/browser/browser/frame_mapping.go#L920-L956","documentation":"parseFrameWaitForSelectorOptions validates the `state` option of frame.waitForSelector/page.waitForSelector against the known DOM element states via DOMElementStateIDFromString. Only 'attached', 'detached', 'visible', and 'hidden' are accepted; any other string produces '%q is not a valid DOM state'.","triggerScenarios":"Calling page.waitForSelector(sel, { state: 'visibility' }) or any value outside the four valid states, e.g. 'visibile' (typo), 'shown', 'stable', 'enabled', or wrong casing such as 'Visible'.","commonSituations":"Porting from Playwright, which additionally accepts 'stable' for waitForSelector; typos like 'visibile'; forgetting that k6 browser only implements a subset of Playwright's state values; mixing up waitForSelector state with waitForFunction or element state APIs.","solutions":["Use one of the four valid states: 'attached', 'detached', 'visible', or 'hidden' (lowercase)","If you need Playwright's 'stable', replace it with 'visible' plus an explicit visibility check","Fix casing and typos — matching is exact string comparison","Consult k6 docs for the exact supported state values in your k6 version"],"exampleFix":"// before\nawait page.waitForSelector('#btn', { state: 'stable' });\n\n// after\nawait page.waitForSelector('#btn', { state: 'visible' });","handlingStrategy":"validation","validationCode":"const DOM_STATES = ['attached', 'detached', 'visible', 'hidden'];\nfunction validWaitForSelectorOptions(opts) {\n  return opts == null || opts.state === undefined || DOM_STATES.includes(opts.state);\n}","typeGuard":"function isValidDOMState(v) {\n  return ['attached', 'detached', 'visible', 'hidden'].includes(v);\n}","tryCatchPattern":"try {\n  await page.waitForSelector(sel, { state: 'visible' });\n} catch (e) {\n  if (String(e).includes('is not a valid DOM state')) {\n    throw new Error('state must be attached|detached|visible|hidden: ' + e);\n  }\n  throw e;\n}","preventionTips":["Remember only four states exist: attached, detached, visible, hidden","Replace Playwright-only 'stable' with 'visible' plus an explicit wait","Keep state values lowercase and free of typos","Share a constants file for valid DOM states across your test suite"],"tags":["browser","waitforselector","dom-state","enum"],"backgroundTag":"invalid-enum-value","analyzedSha":"8d06114777191d21ef885d05c5f8aa9e1ed838ae","analyzedAt":"2026-09-14T20:10:14.619Z","contentChangedAt":"2026-09-14T20:10:14.619Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}