grafana/k6 · error
internal error while auto attaching to browser pages
Error message
internal error while auto attaching to browser pages: %w
What it means
Failure of the CDP target.setAutoAttach command (with flatten) during page creation, which makes the browser auto-attach to new child targets (iframes/popups). Marked 'internal' because the user cannot influence it directly; it fires when the DevTools session rejects the command during page setup.
Solutions
- Retry page/browser creation — usually a transient CDP startup race
- Verify browser launch succeeded and is not resource-starved
- Report as a k6/browser bug if it reproduces reliably on a healthy browser
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at internal/js/modules/k6/browser/common/page.go:354 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/77fde1b4f3706610.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/browser/common/page.go:356
p.frameManager = NewFrameManager(ctx, s, &p, p.timeoutSettings, p.logger)
p.mainFrameSession, err = NewFrameSession(p.ctx, p.teardownCtx, s, &p, nil, tid, p.logger, true)
if err != nil {
p.logger.Debugf("Page:NewPage:NewFrameSession:return", "sid:%v tid:%v err:%v",
p.sessionID(), tid, err)
return nil, err
}
p.frameSessionsMu.Lock()
p.frameSessions[cdp.FrameID(tid)] = p.mainFrameSession
p.frameSessionsMu.Unlock()
p.Mouse = NewMouse(ctx, s, p.frameManager.MainFrame(), bctx.timeoutSettings, p.Keyboard)
p.Touchscreen = NewTouchscreen(ctx, s, p.Keyboard)
p.initEvents()
action := target.SetAutoAttach(true, true).WithFlatten(true)
if err := action.Do(cdp.WithExecutor(p.ctx, p.session)); err != nil {
return nil, fmt.Errorf("internal error while auto attaching to browser pages: %w", err)
}
add := runtime.AddBinding(webVitalBinding)
if err := add.Do(cdp.WithExecutor(p.ctx, p.session)); err != nil {
return nil, fmt.Errorf("internal error while adding binding to page: %w", err)
}
if err := bctx.applyAllInitScripts(&p); err != nil {
return nil, fmt.Errorf("internal error while applying init scripts to page: %w", err)
}
return &p, nil
}
func (p *Page) initEvents() {
p.logger.Debugf("Page:initEvents",
"sid:%v tid:%v", p.session.ID(), p.targetID)
View on GitHub (pinned to 3fcf5388d7)