{"record":{"id":"bbdc3af23c473c19","repo":"grafana/k6","slug":"checking-is-q-in-viewport-unexpected-type-t","errorCode":null,"errorMessage":"checking is %q in viewport: unexpected type %T","messagePattern":"checking is %q in viewport: unexpected type %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/frame.go","lineNumber":1602,"sourceCode":"func (f *Frame) isInViewport(selector string, opts *FrameIsInViewportOptions) (bool, error) {\n\tisInViewport := func(apiCtx context.Context, handle *ElementHandle) (any, error) {\n\t\tv, err := handle.isInViewport(apiCtx, opts.Ratio)\n\t\tif errors.Is(err, ErrTimedOut) { // We don't care about timeout errors here!\n\t\t\treturn v, nil\n\t\t}\n\t\treturn v, err\n\t}\n\tact := f.newAction(\n\t\tselector, DOMElementStateAttached, opts.Strict, isInViewport, []string{}, false, withRetry, true, opts.Timeout,\n\t)\n\tv, err := call(f.ctx, act, opts.Timeout)\n\tif err != nil {\n\t\treturn false, errorFromDOMError(err)\n\t}\n\n\tbv, ok := v.(bool)\n\tif !ok {\n\t\treturn false, fmt.Errorf(\"checking is %q in viewport: unexpected type %T\", selector, v)\n\t}\n\n\treturn bv, nil\n}\n\n// ID returns the frame id.\nfunc (f *Frame) ID() string {\n\tf.propertiesMu.RLock()\n\tdefer f.propertiesMu.RUnlock()\n\n\treturn f.id.String()\n}\n\n// Locator creates and returns a new locator for this frame.\nfunc (f *Frame) Locator(selector string, opts *LocatorOptions) *Locator {\n\tf.log.Debugf(\"Frame:Locator\", \"fid:%s furl:%q selector:%q opts:%+v\", f.ID(), f.URL(), selector, opts)\n\n\treturn NewLocator(f.ctx, opts, selector, f, f.log)","sourceCodeStart":1584,"sourceCodeEnd":1620,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/frame.go#L1584-L1620","documentation":"Internal invariant error in k6 browser's frame.isInViewport: after the action succeeds, the value returned by the CDP evaluation must be a Go bool; the type assertion v.(bool) failed. It signals an unexpected protocol/serialization result, not a user-input problem.","triggerScenarios":"Calling elementHandle.../page.isInViewPort-style internal path where the in-viewport ratio evaluation returns a non-bool remote value — realistically only from a Chromium/k6 version mismatch or an internal bug, since the evaluated JS always produces a boolean.","commonSituations":"Upgrading k6 or the bundled Chromium to mismatched versions; virtually never seen in normal test runs because the injected script returns a boolean by construction.","solutions":["Re-run the test once to rule out a transient CDP glitch","Check for a k6/Chromium version mismatch and align versions (k6 >= the version that shipped your browser module)","Report it as a k6 bug at https://github.com/grafana/k6/issues with the script and k6 version","Work around by checking visibility and bounding box via elementHandle.boundingBox() instead"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const inVp = frame.isInViewPort ? page.$eval(sel, el => { /* bbox ratio check */ return true; }) : false;\n} catch (e) {\n  console.log(`viewport check failed (likely internal): ${e}`);\n}","preventionTips":["Keep k6 and its bundled Chromium versions matched and current","Pin the k6 version in CI so protocol behavior cannot drift silently"],"tags":["k6","browser","internal","type-assertion","viewport"],"backgroundTag":"type-assertion-failed","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"}