{"record":{"id":"23bbcda5e72d996d","repo":"grafana/k6","slug":"getting-bounding-box-w","errorCode":null,"errorMessage":"getting bounding box: %w","messagePattern":"getting bounding box: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/element_handle.go","lineNumber":828,"sourceCode":"\t\t}\n\t}\n\n\treturn strings.Join(parts, \" >> \")\n}\n\n// AsElement returns this element handle.\nfunc (h *ElementHandle) AsElement() *ElementHandle {\n\treturn h\n}\n\n// BoundingBox returns this element's bounding box.\nfunc (h *ElementHandle) BoundingBox() (*Rect, error) {\n\tbbox, err := h.boundingBox()\n\tif err != nil && strings.Contains(err.Error(), \"Could not compute box model\") {\n\t\treturn nil, fmt.Errorf(\"%w: %w\", ErrElementNotVisible, err)\n\t}\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"getting bounding box: %w\", err)\n\t}\n\treturn bbox, nil\n}\n\n// Click scrolls element into view and clicks in the center of the element\n// TODO: look into making more robust using retries\n// (see: https://github.com/microsoft/playwright/blob/master/src/server/dom.ts#L298)\nfunc (h *ElementHandle) Click(opts *ElementHandleClickOptions) error {\n\tclick := h.newPointerAction(\n\t\tfunc(apiCtx context.Context, handle *ElementHandle, p *Position) (any, error) {\n\t\t\treturn nil, handle.click(p, opts.ToMouseClickOptions())\n\t\t},\n\t\t&opts.ElementHandleBasePointerOptions,\n\t)\n\tif _, err := call(h.ctx, click, opts.Timeout); err != nil {\n\t\treturn fmt.Errorf(\"clicking on element: %w\", err)\n\t}\n\tapplySlowMo(h.ctx)","sourceCodeStart":810,"sourceCodeEnd":846,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/element_handle.go#L810-L846","documentation":"BoundingBox()'s generic failure branch: the underlying h.boundingBox() call errored without the 'Could not compute box model' signature, so it is not classified as invisibility. Causes are infrastructure-level: CDP GetBoxModel protocol errors, 'Could not compute box model' variants phrased differently, session/target closed, node detached, or frame position lookup failure.","triggerScenarios":"Measuring or clicking an element after the page has navigated/crashed (stale remote object ID), the CDP session being closed mid-call, cross-origin frame position failures in h.frame.position(), or the DOM node being pruned between resolution and measurement.","commonSituations":"Long scripts holding element handles across navigations; browser or renderer crash under memory pressure in CI; targets swapped by SPA frameworks; flaky network to a remote Chrome (k6 cloud browsers).","solutions":["Re-acquire the element handle right before the measurement instead of caching it across navigations","Check page/browser liveness around the call (page.isClosed(), browser context state) and restart the iteration on session errors","Retry once — transient CDP errors after load events often clear","If it correlates with heavy pages in CI, raise browser memory or reduce parallelism"],"exampleFix":"// before\nconst el = await page.$('#target');\nawait page.goto(nextUrl);\nconst box = await el.boundingBox(); // stale handle\n\n// after\nawait page.goto(nextUrl);\nconst el = await page.$('#target');\nconst box = await el.boundingBox();","handlingStrategy":"retry","validationCode":"if (page.isClosed()) throw new Error('page closed; re-create before measuring');\nconst el = await page.$('#target'); // fresh handle right before use","typeGuard":null,"tryCatchPattern":"let box;\nfor (let attempt = 0; attempt < 2; attempt++) {\n  try {\n    box = await el.boundingBox();\n    break;\n  } catch (e) {\n    if (attempt === 1 || page.isClosed()) throw e;\n    await page.waitForTimeout(500);\n    el = await page.$('#target'); // re-acquire handle\n  }\n}","preventionTips":["Never cache element handles across page.goto/reload","Re-query handles immediately before geometry-dependent actions","Monitor browser health in long CI runs to catch renderer crashes"],"tags":["browser","bounding-box","cdp","stale-element","session-closed"],"backgroundTag":"cdp-protocol-error","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"}