{"record":{"id":"980e1dff7f24abef","repo":"grafana/k6","slug":"checking-is-q-checked-unexpected-type-t","errorCode":null,"errorMessage":"checking is %q checked: unexpected type %T","messagePattern":"checking is %q checked: unexpected type %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/frame.go","lineNumber":759,"sourceCode":"func (f *Frame) isChecked(selector string, opts *FrameIsCheckedOptions) (bool, error) {\n\tisChecked := func(apiCtx context.Context, handle *ElementHandle) (any, error) {\n\t\tv, err := handle.isChecked(apiCtx, 0) // Zero timeout when checking state\n\t\tif errors.Is(err, ErrTimedOut) {      // We don't care about timeout errors here!\n\t\t\treturn v, nil\n\t\t}\n\t\treturn v, err\n\t}\n\tact := f.newAction(\n\t\tselector, DOMElementStateAttached, opts.Strict, isChecked, []string{}, false, withRetry, true, opts.Timeout,\n\t)\n\tv, err := call(f.ctx, act, opts.Timeout)\n\tif err != nil {\n\t\treturn false, errorFromDOMError(err)\n\t}\n\n\tbv, ok := v.(bool)\n\tif !ok {\n\t\treturn false, fmt.Errorf(\"checking is %q checked: unexpected type %T\", selector, v)\n\t}\n\n\treturn bv, nil\n}\n\n// Content returns the HTML content of the frame.\nfunc (f *Frame) Content() (string, error) {\n\tf.log.Debugf(\"Frame:Content\", \"fid:%s furl:%q\", f.ID(), f.URL())\n\n\tjs := `() => {\n\t\tlet content = '';\n\t\tif (document.doctype) {\n\t\t\tcontent = new XMLSerializer().serializeToString(document.doctype);\n\t\t}\n\t\tif (document.documentElement) {\n\t\t\tcontent += document.documentElement.outerHTML;\n\t\t}\n\t\treturn content;","sourceCodeStart":741,"sourceCodeEnd":777,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/frame.go#L741-L777","documentation":"After the isChecked action succeeds, k6 type-asserts the action's return value to bool. If the internal pipeline produced anything else (nil, string), the assertion fails. This is an internal invariant violation — the DOM action contract (bool return) was broken, and it usually indicates a module bug or a highly unusual CDP state, not user error.","triggerScenarios":"handle.isChecked() returning a non-boolean (e.g. nil remote object) for detached/odd elements; internal refactor changing the action return type in a specific k6 version.","commonSituations":"Element detaches exactly between wait success and state read; regression in a k6 browser module release; sporadic under heavy load timing.","solutions":["Wrap in try-catch and fall back to reading state via evaluate (input.checked).","Ensure the element stays attached (waitForSelector visible) before isChecked.","Upgrade k6 to the latest patch — internal assertion failures are treated as module bugs."],"exampleFix":"// before\nconst ok = frame.isChecked('#agree');\n\n// after\nlet ok;\ntry {\n  ok = frame.isChecked('#agree');\n} catch (e) {\n  console.warn('isChecked failed, falling back:', e.message);\n  ok = frame.evaluate('() => document.querySelector(\"#agree\").checked');\n}","handlingStrategy":"try-catch","validationCode":"await frame.waitForSelector(sel, { state: 'attached', timeout: 30000 });","typeGuard":"const isBool = (v) => typeof v === 'boolean';","tryCatchPattern":"let ok;\ntry {\n  ok = frame.isChecked(sel);\n} catch (e) {\n  ok = frame.evaluate('(s) => !!document.querySelector(s)?.checked', sel);\n}\nif (!isBool(ok)) throw new Error('unchecked state could not be read');","preventionTips":["Keep a read-state-via-evaluate fallback for flaky elements.","Ensure the element stays attached when its state is read.","Report repeat occurrences as module bugs with a reproducer."],"tags":["browser","ischecked","type-assertion","internal-invariant","fallback"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}