{"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/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/element_handle.go#L810-L846","documentation":"Generic wrapper for any boundingBox() failure that is not the 'Could not compute box model' case: CDP transport errors, 'getting position of parent frame' failures, closed targets, or stale objectIDs.","triggerScenarios":"boundingBox() (directly or via pointer actions) after navigation invalidated the handle's objectID, when the CDP session/target was closed, or when computing the parent frame offset failed for elements inside iframes.","commonSituations":"Racing page navigation; browser/target crash under memory pressure; iframe position lookup failing during frame teardown; heavy parallel load causing CDP hiccups.","solutions":["Re-locate the element and retry once","Make sure no navigation is in flight when geometry is requested","Read the wrapped CDP error: 'target closed'/'session detached' means browser-side death, not an element problem","Stabilize browser resources (memory, concurrency) if crashes recur"],"exampleFix":"// before\nconst box = await staleHandle.boundingBox(); // getting bounding box: ... target closed\n\n// after\nconst box = await (await page.$(sel)).boundingBox();","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const box = await handle.boundingBox();\n} catch (e) {\n  if (String(e).includes('getting bounding box')) {\n    handle = await page.$(sel); // refresh stale handle, retry once\n    return await handle.boundingBox();\n  }\n  throw e;\n}","preventionTips":["Don't hold handles across navigations","Check for 'target closed' in the cause — that indicates browser death, not element state"],"tags":["browser","bounding-box","cdp","stale-handle"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}