grafana/k6 · error

getting frame owner: %w

Error message

getting frame owner: %w

What it means

Page.getFrameElement asked chromium (DOM.getFrameOwner) for the owner element of a frame and the CDP call failed with something other than the recognized 'frame with the given id was not found' message (which is mapped to a friendly 'frame has been detached' error). This happens while resolving frameElement() for an iframe — the parent session executed the query but chromium rejected it.

Source

Thrown at internal/js/modules/k6/browser/common/page.go:671

		return nil, errors.New("frame has been detached 1")
	}

	rootFrame := f
	for ; rootFrame.parentFrame != nil; rootFrame = rootFrame.parentFrame {
	}

	parentSession, ok := p.getFrameSession(cdp.FrameID(rootFrame.ID()))
	if !ok {
		return nil, errors.New("parent frame has been detached")
	}

	action := dom.GetFrameOwner(cdp.FrameID(f.ID()))
	backendNodeID, _, err := action.Do(cdp.WithExecutor(p.ctx, parentSession.session))
	if err != nil {
		if strings.Contains(err.Error(), "frame with the given id was not found") {
			return nil, errors.New("frame has been detached")
		}
		return nil, fmt.Errorf("getting frame owner: %w", err)
	}

	parent = f.parentFrame
	if parent == nil {
		return nil, errors.New("frame has been detached 2")
	}
	return parent.adoptBackendNodeID(mainWorld, backendNodeID)
}

func (p *Page) getOwnerFrame(apiCtx context.Context, h *ElementHandle) (cdp.FrameID, error) {
	p.logger.Debugf("Page:getOwnerFrame", "sid:%v", p.sessionID())

	// document.documentElement has frameId of the owner frame
	pageFn := `
		node => {
			const doc = node;
      		if (doc.documentElement && doc.documentElement.ownerDocument === doc)
        		return doc.documentElement;

View on GitHub (pinned to 93accf6570)

Solutions

  1. Wait for the frame/iframe to be attached and stable (frame.waitForNavigation or waiting on a selector inside the frame) before frameElement()
  2. Re-fetch the frame reference after navigations instead of caching it across goto/click
  3. Do not call frame APIs once the page is closing; guard with page.isClosed()
  4. If chromium's error text changed between versions, upgrade k6 so the friendly mapping keeps up — otherwise report it as a bug with the wrapped CDP error

Example fix

// before
const frame = page.frames()[1];
const el = await frame.frameElement(); // during iframe navigation

// after
await page.waitForSelector('#myiframe >>> *'); // iframe content settled
const frame = page.frames().find(f => f.name === 'myiframe');
const el = await frame.frameElement();
Defensive patterns

Strategy: try-catch

Validate before calling

if (page.isClosed()) { /* skip frameElement(): frame tree is going away */ }

Try / catch

try {
  const el = await frame.frameElement();
} catch (e) {
  const s = String(e);
  if (/frame .*detached|getting frame owner/.test(s)) return null; // iframe churn
  throw e;
}

Prevention

When it happens

Trigger: Calling frameElement() (directly or via APIs that resolve an iframe's ElementHandle) when the frame tree is in flux: the iframe navigated and its old frame id is stale in a way that doesn't match the friendly error text, the parent frame session is mid-detach, or the page is closing so DOM.resolveNode-style follow-ups fail.

Common situations: Tests that grab content inside iframes while the outer page keeps navigating or redirecting; ad/widget iframes that destroy themselves mid-test; calling frameElement() on a frame whose parent already detached during teardown.

Related errors


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