{"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/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/element_handle.go#L399-L435","documentation":"isInViewport() evaluates injected.isInViewport, which must return a boolean or an 'error:...' string. Any other Go type from the evaluation triggers this error, indicating the injected-script contract broke or the context died mid-eval.","triggerScenarios":"Viewport-membership checks (used by actionability logic and internal waits) when the eval returns undefined or an object — execution context destroyed during evaluation or an injected-script/binary version mismatch.","commonSituations":"Navigation or iframe teardown racing the check; custom builds with stale injected script; very rare on stock releases.","solutions":["Retry after the page settles","Upgrade to a clean, matching k6 version","Avoid racing navigation: wait for load state before asserting viewport visibility","File an issue with a reproduction if it recurs on a stock build"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const visible = await handle.isVisible(); // related state checks\n} catch (e) {\n  if (String(e).includes('unexpected type')) { /* retry with fresh handle */ } \n  else { throw e; }\n}","preventionTips":["Don't run viewport assertions during navigation","Re-locate handles after frame changes"],"tags":["browser","viewport","injected-script","internal-invariant"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}