grafana/k6 · error
getting bounding box model of DOM node: %w
Error message
getting bounding box model of DOM node: %w
What it means
ElementHandle.boundingBox issues the CDP dom.GetBoxModel call for the handle's remote object; if the protocol call fails, the error is wrapped with this text. Typical underlying failures: the node was detached/removed (stale object ID), the frame navigated away, or the session is gone.
Source
Thrown at internal/js/modules/k6/browser/common/element_handle.go:68
frame *Frame
}
// String returns a string representation of ElementHandle.
// It exists mostly for debugging where we don't want fmt.Sprintf to just
// go through a complex object and try to stringify it.
func (h *ElementHandle) String() string {
return "ElementHandle{" +
" BaseJSHandle: " + h.BaseJSHandle.String() +
" frame: " + h.frame.String() +
"}"
}
func (h *ElementHandle) boundingBox() (*Rect, error) {
var box *dom.BoxModel
var err error
action := dom.GetBoxModel().WithObjectID(h.remoteObject.ObjectID)
if box, err = action.Do(cdp.WithExecutor(h.ctx, h.session)); err != nil {
return nil, fmt.Errorf("getting bounding box model of DOM node: %w", err)
}
if box == nil || box.Border == nil {
return nil, ErrElementNotAttachedToDOM
}
quad := box.Border
x := math.Min(quad[0], math.Min(quad[2], math.Min(quad[4], quad[6])))
y := math.Min(quad[1], math.Min(quad[3], math.Min(quad[5], quad[7])))
width := math.Max(quad[0], math.Max(quad[2], math.Max(quad[4], quad[6]))) - x
height := math.Max(quad[1], math.Max(quad[3], math.Max(quad[5], quad[7]))) - y
position, err := h.frame.position()
if err != nil {
return nil, fmt.Errorf("getting position of parent frame: %w", err)
}
return &Rect{X: x + position.X, Y: y + position.Y, Width: width, Height: height}, nilView on GitHub (pinned to 93accf6570)
Solutions
- Re-query the element immediately before measuring instead of reusing a stale handle.
- Wait for the element to be attached/visible first (locator with waitFor / expect-style waits) before boundingBox.
- Do not navigate between acquiring the handle and calling boundingBox.
- If it happens inside click(), prefer locator-based clicks with a retry on this specific error.
Example fix
// before
const el = page.locator('#submit');
const handle = await el.getElementHandle();
await page.waitForTimeout(5000); // SPA re-renders, handle goes stale
await handle.boundingBox(); // getting bounding box model of DOM node: ...
// after
const handle = await page.locator('#submit').getElementHandle(); // re-query late
await handle.boundingBox(); Defensive patterns
Strategy: retry
Validate before calling
// re-query the element fresh instead of reusing a possibly stale handle const handle = await page.locator(sel).getElementHandle(); // measure immediately, in the same tick — no sleeps or navigations in between
Try / catch
try {
await handle.boundingBox();
} catch (e) {
if (/getting bounding box model of DOM node/.test(String(e))) {
const fresh = await page.locator(sel).getElementHandle(); // node may have been re-mounted
return await fresh.boundingBox();
}
throw e;
} Prevention
- Never hold element handles across navigations or long waits; re-query before use.
- Wait for visibility (locator.waitFor) before geometry-sensitive operations.
- In dynamic SPAs, wrap boundingBox/click in a single-retry helper keyed to this message.
When it happens
Trigger: Calling elementHandle.boundingBox() (directly, or via click() which resolves a clickable point through it) after the element left the DOM, after a navigation replaced the document, or on a handle from a closed page.
Common situations: SPA re-rendering between locator query and boundingBox (React re-mounts the node); ad/promo overlays removing the target; holding element handles across page.goto and reusing them.
Related errors
- getting position of parent frame: %w
- element is not attached to the DOM
- getting bounding box of parent frame: %w
- finding clickable point: %w
- %w: %w
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/34ee0896280f7c82.
Report an issue: GitHub.