grafana/k6 · error

getting bounding box model of DOM node

Error message

getting bounding box model of DOM node: %w

What it means

The CDP dom.GetBoxModel call failed for the element's remote object while computing its bounding box. This wraps a protocol error — commonly the node being detached from the DOM, an expired remote object, or a dropped session.

Solutions

  1. Re-query the element before calling boundingBox()/screenshot()
  2. Wait for the element to be attached: waitForSelector(sel, {state:'attached'})
  3. Check for navigation that invalidated the element handle
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at internal/js/modules/k6/browser/common/element_handle.go:68 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of grafana/k6@3fcf5388d7 (2026-08-18). Data as JSON: /api/errors/34ee0896280f7c82. Report an issue: GitHub.

Appendix: 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}, nil

View on GitHub (pinned to 3fcf5388d7)