{"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/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/element_handle.go#L1215-L1251","documentation":"Returned by ElementHandle.Query as a defensive type guard: the injected querySelector evaluation returned a result that does not implement JSHandleAPI, so it cannot be treated as a handle. This should not happen under normal operation; it indicates an unexpected evaluation result type (e.g. a primitive returned by value) reaching handle-only code.","triggerScenarios":"Thrown at internal/js/modules/k6/browser/common/element_handle.go:1233 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Report as a k6 browser module bug if reproducible, including the selector and page","Verify the injected script bundle matches the k6 version (no mixed builds)","Avoid non-standard monkey-patching of querySelector results in page scripts"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}