{"record":{"id":"7ac8a005b8a4a2c9","repo":"grafana/k6","slug":"checking-element-is-in-viewport-unexpected-type","errorCode":null,"errorMessage":"checking element is in viewport: unexpected type %T","messagePattern":"checking element is in viewport: unexpected type %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/element_handle.go","lineNumber":417,"sourceCode":"\t\t\treturn injected.isInViewport(node, ratio);\n\t\t}\n\t`\n\topts := evalOptions{\n\t\tforceCallable: true,\n\t\treturnByValue: true,\n\t}\n\tresult, err := h.evalWithScript(apiCtx, opts, fn, ratio)\n\tif err != nil {\n\t\treturn false, errorFromDOMError(err)\n\t}\n\tswitch v := result.(type) {\n\tcase string: // An error happened (returned as \"error:...\" from JS)\n\t\treturn false, errorFromDOMError(v)\n\tcase bool:\n\t\treturn v, nil\n\t}\n\n\treturn false, fmt.Errorf(\n\t\t\"checking element is in viewport: unexpected type %T\", result)\n}\n\nfunc (h *ElementHandle) offsetPosition(apiCtx context.Context, offset *Position) (*Position, error) {\n\tfn := `\n\t\t(node, injected) => {\n\t\t\treturn injected.getElementBorderWidth(node);\n\t\t}\n\t`\n\topts := evalOptions{\n\t\tforceCallable: true,\n\t\treturnByValue: true,\n\t}\n\tresult, err := h.evalWithScript(apiCtx, opts, fn)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n","sourceCodeStart":399,"sourceCodeEnd":435,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/element_handle.go#L399-L435","documentation":"Returned by ElementHandle's in-viewport verification: the injected script that checks whether the element intersects the viewport (with the given ratio) returned neither a bool nor a string status. It is an internal type-contract violation; normal outcomes are a bool (is/isn't in viewport) or an 'error:...' string.","triggerScenarios":"Viewport checks performed as part of scrollIntoViewIfNeeded/actionability where the injected script's return value comes back as an unexpected type (object/number/undefined) due to page-side tampering or an internal regression; passing a non-numeric ratio from the API surface would surface earlier as an eval error.","commonSituations":"Pages overriding prototypes that the injected script relies on; version skew in k6 internals; not triggered by ordinary CSS/layout conditions — genuine 'not in viewport' cases return false, not this error.","solutions":["Upgrade k6 to rule out internal regression","Confirm behavior on a static page to rule out app-side script interference","Avoid forcing viewport checks (el.scrollIntoViewIfNeeded already handles scrolling); if it keeps failing, scroll manually via el.evaluate","Report to k6 with a minimal reproducer"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await el.scrollIntoViewIfNeeded();\n} catch (e) {\n  if (/in viewport/.test(String(e))) {\n    await el.evaluate((node) => node.scrollIntoView({ block: 'center' }));\n  } else throw e;\n}","preventionTips":["Set an adequate viewport size (browser context options) so elements can be in view","Scroll containers into view manually when apps use custom scroll areas"],"tags":["browser","viewport","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"}