{"record":{"id":"ee5142637e331b51","repo":"grafana/k6","slug":"getting-bounding-box-of-q-unexpected-type-t","errorCode":null,"errorMessage":"getting bounding box of %q: unexpected type %T","messagePattern":"getting bounding box of %q: unexpected type %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/frame.go","lineNumber":586,"sourceCode":"\n\treturn handle, err\n}\n\nfunc (f *Frame) boundingBox(selector string, opts *FrameBaseOptions) (*Rect, error) {\n\tgetBoundingBox := func(apiCtx context.Context, handle *ElementHandle) (any, error) {\n\t\treturn handle.BoundingBox()\n\t}\n\tact := f.newAction(\n\t\tselector, DOMElementStateAttached, opts.Strict, getBoundingBox, []string{}, false, noRetry, true, opts.Timeout,\n\t)\n\tv, err := call(f.ctx, act, opts.Timeout)\n\tif err != nil {\n\t\treturn nil, errorFromDOMError(err)\n\t}\n\n\tbv, ok := v.(*Rect)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"getting bounding box of %q: unexpected type %T\", selector, v)\n\t}\n\n\treturn bv, nil\n}\n\n// ChildFrames returns a list of child frames.\nfunc (f *Frame) ChildFrames() []*Frame {\n\tf.childFramesMu.RLock()\n\tdefer f.childFramesMu.RUnlock()\n\n\tl := make([]*Frame, 0, len(f.childFrames))\n\tfor child := range f.childFrames {\n\t\tl = append(l, child)\n\t}\n\treturn l\n}\n\n// Click clicks the first element found that matches selector.","sourceCodeStart":568,"sourceCodeEnd":604,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/frame.go#L568-L604","documentation":"After the wait-for-selector action succeeds, Frame.BoundingBox() asserts that the action's return value is a *Rect (produced by ElementHandle.BoundingBox()). If the internal pipeline returned nil or any other Go type, this type assertion fails. This is an internal invariant violation of the k6 browser module, not a user-input error: normally the DOM action returns a Rect or errors out before this line.","triggerScenarios":"Calling frame.boundingBox(selector) (or page.boundingBox) where handle.BoundingBox() returns nil — e.g. the element detaches between the successful wait and the bounding-box CDP call, or the element renders with no layout box (display:none subtree edge cases). Also possible after internal refactors that change the action's return type.","commonSituations":"Element removed/re-rendered by the SPA right after becoming visible; shadow-DOM or zero-size elements; a regression in the k6 browser module after upgrading k6 (internal type changed); intermittent only under load timing.","solutions":["Retry after ensuring the element is stable: await page.waitForSelector(sel, { state: 'visible' }) before boundingBox().","If it repeats on the same element, check the element actually has layout (not display:none / detached) — try frame.evaluate on getBoundingClientRect to compare.","Upgrade to the latest k6 — this code path is internal and such assertion failures have historically been module bugs.","If persistent, report it with a minimal reproducing script at the k6-browser GitHub issues."],"exampleFix":"// before\nconst rect = page.boundingBox('#cart-icon');\n\n// after\nawait page.waitForSelector('#cart-icon', { state: 'visible' });\nconst rect = await (async () => {\n  try {\n    return page.boundingBox('#cart-icon');\n  } catch (e) {\n    console.warn('boundingBox failed, element may have detached:', e.message);\n    return null;\n  }\n})();","handlingStrategy":"try-catch","validationCode":"await page.waitForSelector(sel, { state: 'visible', timeout: 30000 });","typeGuard":"const isRect = (r) => r != null && typeof r === 'object' && ['x','y','width','height'].every((k) => typeof r[k] === 'number');","tryCatchPattern":"try {\n  const rect = page.boundingBox(sel);\n  if (!isRect(rect)) throw new Error('boundingBox returned non-rect');\n} catch (e) {\n  console.warn('boundingBox failed:', e.message);\n}","preventionTips":["Always waitForSelector visible before measuring geometry.","Treat unexpected-type errors as module bugs: pin a known-good k6 version and retest after upgrades.","Add null/shape checks on returned rects before using them."],"tags":["browser","bounding-box","type-assertion","internal-invariant","element-detached"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}