{"record":{"id":"1ff9c50fa455a052","repo":"grafana/k6","slug":"querying-selector-q-wrong-type-t","errorCode":null,"errorMessage":"querying selector %q, wrong type %T","messagePattern":"querying selector %q, wrong type %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/element_handle.go","lineNumber":1233,"sourceCode":"\tquerySelector := `\n\t\t(node, injected, selector, strict) => {\n\t\t\treturn injected.querySelector(selector, strict, node || document);\n\t\t}\n\t`\n\topts := evalOptions{\n\t\tforceCallable: true,\n\t\treturnByValue: false,\n\t}\n\tresult, err := h.evalWithScript(h.ctx, opts, querySelector, parsedSelector, strict)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"querying selector %q: %w\", selector, err)\n\t}\n\tif result == nil {\n\t\treturn nil, nil //nolint:nilnil\n\t}\n\thandle, ok := result.(JSHandleAPI)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"querying selector %q, wrong type %T\", selector, result)\n\t}\n\telement := handle.AsElement()\n\tif element == nil {\n\t\tdefer func() {\n\t\t\tif err := handle.Dispose(); err != nil {\n\t\t\t\terr = fmt.Errorf(\"disposing element handle: %w\", err)\n\t\t\t\trerr = errors.Join(err, rerr)\n\t\t\t}\n\t\t}()\n\t\treturn nil, fmt.Errorf(\"querying selector %q\", selector)\n\t}\n\n\treturn element, nil\n}\n\n// QueryAll queries element subtree for matching elements.\n// If no element matches the selector, the return value resolves to \"null\".\nfunc (h *ElementHandle) QueryAll(selector string) ([]*ElementHandle, error) {","sourceCodeStart":1215,"sourceCodeEnd":1251,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/element_handle.go#L1215-L1251","documentation":"ElementHandle.Query() type-asserted the evaluation result to a JSHandleAPI and got a different Go type (element_handle.go:1233). This is an internal invariant break — the protocol returned an unexpected result shape — not a user-input error. The %T in the message tells maintainers which type leaked through.","triggerScenarios":"A chromium/CDP version returning an unexpected Runtime.callFunctionOn result; a k6 browser-module bug in the evaluation-to-handle plumbing; exotic targets (embedded chromium forks) deviating from the protocol.","commonSituations":"Rare. Appears after upgrading chromium or running against non-standard browsers/WebViews; not reproducible with normal selectors on stock chrome.","solutions":["Upgrade k6 to the latest release (the browser module is under active fix)","Pin/try a different chromium version to rule out a protocol deviation","Report to k6 with the minimal script, the %T value from the message, and browser versions","Work around with page.$()/locator queries on the page instead of element.$()"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { const child = await el.$(sel); }\ncatch (e) { if (/wrong type/.test(e.message)) { /* internal: report + fall back to page.$ */ return await page.$(sel); } throw e; }","preventionTips":["Keep k6 and bundled chromium versions current","Fall back to page-level queries when element-level query hits an invariant error","File issues with the %T value from the message"],"tags":["browser","internal","cdp","invariant"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}