grafana/k6 · error

finding position in frame: %w

Error message

finding position in frame: %w

What it means

After resolving the frame, Frame.position obtains the frame element (the <iframe> in the parent document) and asks for its bounding box; a failure there is wrapped as 'finding position in frame'. It occurs while computing coordinates for pointer actions on elements inside child frames, and means the iframe's box could not be determined.

Source

Thrown at internal/js/modules/k6/browser/common/frame.go:388

	//       website never stops performing network requests.
}

func (f *Frame) position() (*Position, error) {
	frame, ok := f.manager.getFrameByID(cdp.FrameID(f.page.targetID))
	if !ok {
		return nil, fmt.Errorf("could not find frame with id %s", f.page.targetID)
	}
	if frame == f.page.frameManager.MainFrame() {
		return &Position{X: 0, Y: 0}, nil
	}
	element, err := frame.FrameElement()
	if err != nil {
		return nil, err
	}

	box, err := element.BoundingBox()
	if err != nil {
		return nil, fmt.Errorf("finding position in frame: %w", err)
	}

	return &Position{X: box.X, Y: box.Y}, nil
}

func (f *Frame) removeChildFrame(child *Frame) {
	f.log.Debugf("Frame:removeChildFrame", "fid:%s furl:%q cfid:%s curl:%q",
		f.ID(), f.URL(), child.ID(), child.URL())

	f.childFramesMu.Lock()
	defer f.childFramesMu.Unlock()

	delete(f.childFrames, child)
}

func (f *Frame) setContext(world executionWorld, execCtx frameExecutionContext) {
	f.executionContextMu.Lock()
	defer f.executionContextMu.Unlock()

View on GitHub (pinned to 93accf6570)

Solutions

  1. Ensure the iframe is visible and non-zero-sized before interacting inside it (waitForSelector with state:'visible' on the iframe element)
  2. Scroll the iframe into view first
  3. Set a realistic viewport if responsive CSS hides the frame
  4. Retry after the frame becomes visible

Example fix

// before
const frame = page.frames().find(f => f.name() === 'widget');
await frame.click('#inside');

// after
await page.waitForSelector('iframe[name=widget]', { state: 'visible' });
const frame = page.frames().find(f => f.name() === 'widget');
await frame.click('#inside');
Defensive patterns

Strategy: validation

Validate before calling

const fh = await page.waitForSelector('iframe[name=widget]', { state: 'visible' });
const box = await fh.boundingBox();
if (!box || box.width === 0 || box.height === 0) throw new Error('iframe not visible or zero-size');
await frame.click('#inside');

Try / catch

try {
  await frame.click('#inside');
} catch (e) {
  if (/finding position in frame/.test(e.message)) {
    // make the iframe visible/attached, then retry
  } else throw e;
}

Prevention

When it happens

Trigger: Clicking/hovering elements inside an iframe that is hidden (display:none) or zero-sized; the iframe removed from the parent DOM between action start and box calculation; collapsed or scrolled-out iframes where Chrome cannot produce a box.

Common situations: Lazy-loaded iframes not yet visible; ad/consent iframes that get removed mid-action; responsive layouts collapsing the iframe at small viewports.

Related errors


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