grafana/k6 · error

getting bounding box: %w

Error message

getting bounding box: %w

What it means

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.

Source

Thrown at internal/js/modules/k6/browser/common/element_handle.go:828

		}
	}

	return strings.Join(parts, " >> ")
}

// AsElement returns this element handle.
func (h *ElementHandle) AsElement() *ElementHandle {
	return h
}

// BoundingBox returns this element's bounding box.
func (h *ElementHandle) BoundingBox() (*Rect, error) {
	bbox, err := h.boundingBox()
	if err != nil && strings.Contains(err.Error(), "Could not compute box model") {
		return nil, fmt.Errorf("%w: %w", ErrElementNotVisible, err)
	}
	if err != nil {
		return nil, fmt.Errorf("getting bounding box: %w", err)
	}
	return bbox, nil
}

// Click scrolls element into view and clicks in the center of the element
// TODO: look into making more robust using retries
// (see: https://github.com/microsoft/playwright/blob/master/src/server/dom.ts#L298)
func (h *ElementHandle) Click(opts *ElementHandleClickOptions) error {
	click := h.newPointerAction(
		func(apiCtx context.Context, handle *ElementHandle, p *Position) (any, error) {
			return nil, handle.click(p, opts.ToMouseClickOptions())
		},
		&opts.ElementHandleBasePointerOptions,
	)
	if _, err := call(h.ctx, click, opts.Timeout); err != nil {
		return fmt.Errorf("clicking on element: %w", err)
	}
	applySlowMo(h.ctx)

View on GitHub (pinned to 93accf6570)

Solutions

  1. Re-locate the element and retry once
  2. Make sure no navigation is in flight when geometry is requested
  3. Read the wrapped CDP error: 'target closed'/'session detached' means browser-side death, not an element problem
  4. Stabilize browser resources (memory, concurrency) if crashes recur

Example fix

// before
const box = await staleHandle.boundingBox(); // getting bounding box: ... target closed

// after
const box = await (await page.$(sel)).boundingBox();
Defensive patterns

Strategy: try-catch

Try / catch

try {
  const box = await handle.boundingBox();
} catch (e) {
  if (String(e).includes('getting bounding box')) {
    handle = await page.$(sel); // refresh stale handle, retry once
    return await handle.boundingBox();
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: Racing page navigation; browser/target crash under memory pressure; iframe position lookup failing during frame teardown; heavy parallel load causing CDP hiccups.

Related errors


AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15). Data as JSON: /api/errors/23bbcda5e72d996d. Report an issue: GitHub.