grafana/k6 · error

getting position of parent frame: %w

Error message

getting position of parent frame: %w

What it means

After computing the element's own quad in boundingBox(), k6 adds the owning frame's position via h.frame.position(). If that lookup fails (frame detached from the frame tree, page unavailable), the error is wrapped as 'getting position of parent frame'. It only affects elements inside iframes, since top-frame positions resolve trivially.

Source

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

	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
}

// translatePointToPage translates the point to the page's coordinates if the
// point is relative to the parent frame.
func (h *ElementHandle) translatePointToPage(apiCtx context.Context, point Position) (Position, error) {
	h.logger.Debugf("ElementHandle:translatePointToPage", "point before translation: %v", point)

	frame, err := h.ownerFrame(apiCtx)
	if err != nil {
		return Position{}, fmt.Errorf("checking hit target at %v: %w", point, err)
	}

	if frame == nil || frame.parentFrame == nil {
		h.logger.Debugf("ElementHandle:translatePointToPage", "no parent frame")
		return point, nil

View on GitHub (pinned to 93accf6570)

Solutions

  1. Re-acquire the frame and element right before interacting (fresh page.frameLocator(...)/locator query).
  2. Wait for the iframe and its content to finish loading before measuring (frame.waitForNavigation or waiting on an element inside it).
  3. Avoid interacting with iframes that scripts can remove; wait for stability or retry once.
  4. If the iframe is optional, treat this error as a signal it is gone and skip the step.

Example fix

// before
const frame = page.frame({ url: /oauth/ });
const btn = await frame.locator('#approve').getElementHandle();
await sleep(3000);                  // iframe gets removed meanwhile
await btn.click();                  // getting position of parent frame: ...

// after
const btn = await page.frame({ url: /oauth/ }).locator('#approve').getElementHandle();
await btn.click();
Defensive patterns

Strategy: retry

Validate before calling

// confirm the iframe (and its owner) still exists before measuring
const frame = page.frames().find((f) => f.url().includes('widget'));
if (!frame) throw new Error('iframe gone before measurement');
const handle = await frame.locator(sel).getElementHandle();
await handle.boundingBox();

Try / catch

try {
  await handle.boundingBox();
} catch (e) {
  if (/getting position of parent frame/.test(String(e))) {
    const f2 = page.frames().find((f) => f.url().includes('widget'));
    if (!f2) return null;               // iframe legitimately removed
    return await (await f2.locator(sel).getElementHandle()).boundingBox();
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling boundingBox()/click() on an element inside an iframe whose frame was detached (iframe removed from DOM, navigation inside the iframe) between the box-model call and the position lookup.

Common situations: Dynamic iframes (ads, embeds, OAuth popups) removed mid-interaction; iframe content navigating while k6 measures; reusing handles into frames that were closed.

Related errors


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