{"record":{"id":"e63c8166b732fb60","repo":"grafana/k6","slug":"unexpected-result-type-while-getting-document-elem","errorCode":null,"errorMessage":"unexpected result type while getting document element: %T","messagePattern":"unexpected result type while getting document element: %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/element_handle.go","lineNumber":1140,"sourceCode":"\t\t(node, injected) => {\n\t\t\treturn injected.getDocumentElement(node);\n\t\t}\n\t`\n\topts := evalOptions{\n\t\tforceCallable: true,\n\t\treturnByValue: false,\n\t}\n\tres, err := h.evalWithScript(h.ctx, opts, fn)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"getting document element: %w\", err)\n\t}\n\tif res == nil {\n\t\treturn nil, errors.New(\"getting document element: nil document\")\n\t}\n\n\tdocumentHandle, ok := res.(*ElementHandle)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"unexpected result type while getting document element: %T\", res)\n\t}\n\tdefer func() {\n\t\tif err := documentHandle.Dispose(); err != nil {\n\t\t\terr = fmt.Errorf(\"disposing document element: %w\", err)\n\t\t\trerr = errors.Join(err, rerr)\n\t\t}\n\t}()\n\n\tif documentHandle.remoteObject.ObjectID == \"\" {\n\t\treturn nil, err\n\t}\n\n\tvar node *cdp.Node\n\taction := dom.DescribeNode().WithObjectID(documentHandle.remoteObject.ObjectID)\n\tif node, err = action.Do(cdp.WithExecutor(h.ctx, h.session)); err != nil {\n\t\treturn nil, fmt.Errorf(\"getting node in frame: %w\", err)\n\t}\n\tif node == nil || node.FrameID == \"\" {","sourceCodeStart":1122,"sourceCodeEnd":1158,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/element_handle.go#L1122-L1158","documentation":"Internal invariant failure inside ElementHandle.ownerFrame(): the injected getDocumentElement evaluation returned a result, but it was not an *ElementHandle (e.g. null/undefined or a non-node remote object). This indicates the injected script could not resolve a document element from the given node - usually a protocol/version mismatch or a k6 bug rather than script misuse.","triggerScenarios":"The evaluation returns a non-node value for getDocumentElement - seen with Chromium/CDP versions mismatched to the k6 release, handles on unusual nodes (e.g. already-collected documents), or k6 regressions. Rare in normal use.","commonSituations":"Canary/newer Chromium against an older k6; custom browser executables; calling ownerFrame on document-level handles.","solutions":["Upgrade k6 to the latest release","Pin a Chromium version compatible with your k6 release","Work around by getting the frame via evaluate on contentWindow/frameElement","Report to k6 with the script and browser version"],"exampleFix":"// before\nconst f = await h.ownerFrame();\n// after\nawait page.waitForLoadState('load');\nconst f = await h.ownerFrame();\nif (!f) throw new Error('ownerFrame returned no frame');","handlingStrategy":"try-catch","validationCode":"await page.waitForLoadState('load');\nconst el = await page.$('#in-frame');\nconst frame = el ? await el.ownerFrame() : null;\nif (!frame) throw new Error('no frame resolved');","typeGuard":null,"tryCatchPattern":"try {\n  return await handle.ownerFrame();\n} catch (e) {\n  if (String(e).includes('unexpected result type')) {\n    return null; // signal caller to fall back to evaluate-based frame detection\n  }\n  throw e;\n}","preventionTips":["Keep k6 and Chromium versions aligned","Check the returned frame for null before using it","Report persistent occurrences to k6 maintainers"],"tags":["browser","internal","type-assertion","owner-frame","compatibility"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}