{"record":{"id":"067b05630519f0ff","repo":"grafana/k6","slug":"checking-state-q-of-element-q","errorCode":null,"errorMessage":"checking state %q of element %q","messagePattern":"checking state %q of element %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/element_handle.go","lineNumber":205,"sourceCode":"\t\t\treturn injected.checkElementState(node, state);\n\t\t}\n\t`\n\topts := evalOptions{\n\t\tforceCallable: true,\n\t\treturnByValue: true,\n\t}\n\tresult, err := h.evalWithScript(h.ctx, opts, fn, state)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tswitch v := result.(type) {\n\tcase string: // An error happened (returned as \"error:...\" from JS)\n\t\treturn nil, errorFromDOMError(v)\n\tcase bool:\n\t\treturn &v, nil\n\t}\n\n\treturn nil, fmt.Errorf(\n\t\t\"checking state %q of element %q\", state, reflect.TypeOf(result))\n}\n\nfunc (h *ElementHandle) click(p *Position, opts *MouseClickOptions) error {\n\treturn h.frame.page.Mouse.click(p.X, p.Y, opts)\n}\n\n// This will get the clickable point of the element relative to the page even\n// when the element is in an iframe. In some cases this isn't the case and we\n// need to translate the point to the page.\nfunc (h *ElementHandle) clickablePoint() (*Position, error) {\n\tr, err := h.BoundingBox()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"finding clickable point: %w\", err)\n\t}\n\treturn &Position{X: r.X + r.Width/2, Y: r.Y + r.Height/2}, nil\n}\n","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/element_handle.go#L187-L223","documentation":"Returned by the per-state element check (used by waitFor state=visible/hidden/enabled/... style waits): the injected script evaluated successfully but its return value was neither a string ('done'/'error:...' protocol) nor a bool. This is an internal invariant violation of the Go/JS contract inside the k6 browser module, not a normal page condition.","triggerScenarios":"h.evalWithScript with the state-checking JS returns an unexpected type (number, object, undefined) because the injected script was corrupted, a page overrode primitives used by the evaluation, or an internal regression changed the protocol; any waitFor* on element state can surface it.","commonSituations":"Pages that monkey-patch Function.prototype/JSON or define hostile prototypes breaking the injected script; version mismatches after upgrading k6 where the injected JS bundle changed; extremely rare in stock usage.","solutions":["Upgrade (or pin) k6 to a version where the injected-script contract matches the Go side","Test the same script against a plain page (example.com) to confirm it is page-specific interference","If reproducible on a minimal page, file a k6 issue with the script, selector, and state that triggered it","As a workaround, replace state waits with an explicit condition via el.getAttribute/isVisible polling"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await el.waitFor({ state: 'visible' });\n} catch (e) {\n  if (/checking state/.test(String(e))) {\n    // internal eval contract issue: report it, then fall back to polling\n    for (let i = 0; i < 50 && !(await el.isVisible()); i++) {\n      await page.waitForTimeout(200);\n    }\n  } else throw e;\n}","preventionTips":["Pin a known-good k6 version in CI so injected scripts and runtime stay in sync","Avoid app pages that patch built-ins when testing module internals"],"tags":["browser","internal","js-evaluation","invariant"],"backgroundTag":"browser-unexpected-eval-result","analyzedSha":"3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}