grafana/k6 · warning
attaching new page
Error message
attaching new page: %w
What it means
After a new Page is created, attachNewPage registers it in the browser's pages map; the only error it can return is errBrowserClosing, and the caller explicitly filters that case out (logging and closing the page instead). This residual error therefore fires only if attachNewPage fails for a non-closing reason, which the current code cannot produce — it is a defensive near-unreachable branch guarding internal invariants.
Solutions
- Upgrade to the latest k6 release in case it is a fixed regression
- Capture K6_BROWSER_LOG=debug output and the script that triggers it
- Reduce concurrency to rule out resource exhaustion corrupting teardown ordering
- Open a k6 issue with the reproduction and debug log
Defensive patterns
Strategy: try-catch
Try / catch
try {
await page.goto(url);
} catch (e) {
if (String(e).includes('attaching new page')) {
// internal invariant break; capture logs, retry the step once
await sleep(1000);
await page.goto(url);
}
} Prevention
- Run the latest k6 release (defensive branch; older builds may have races)
- Capture K6_BROWSER_LOG=debug output when it appears
- Report reproductions upstream
When it happens
Trigger: Not producible by current code paths: attachPage only returns errBrowserClosing, which is filtered above. Seeing it implies an internal state corruption, a k6 bug, or a forked build violating the invariant.
Common situations: Not seen on stock builds; if it appears, it usually accompanies a k6 regression or heavily patched fork.
Related errors
- already belongs to the same execution context
- browser is closing
- can't fetch the page for unknown reason
- checking element is in viewport: unexpected type %T
- checking is in viewport: unexpected type %T
AI-assisted analysis of grafana/k6@3fcf5388d7 (2026-08-18).
Data as JSON: /api/errors/a9dd6cdf56ba65f9.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/browser/common/browser.go:332
b.pagesMu.RUnlock()
}
p, err := NewPage(b.vuCtx, session, browserCtx, targetPage.TargetID, opener, isPage, b.logger)
if err != nil && b.isPageAttachmentErrorIgnorable(ev, session, err) {
// Always release: isPageAttachmentErrorIgnorable can also return
// true when only this VU's context ended, while the browser
// instance stays alive and shared with other VUs.
detachSession(session)
return nil // Ignore this page.
}
if err != nil {
return fmt.Errorf("creating a new %s: %w", targetPage.Type, err)
}
// This prevents a race where Close() sets closing and snapshots
// pages, but a new page is inserted outside that snapshot.
if err := b.attachNewPage(p, ev); err != nil {
if !errors.Is(err, errBrowserClosing) {
return fmt.Errorf("attaching new page: %w", err)
}
b.logger.Debugf(
"Browser:onAttachedToTarget",
"rejected page attachment; browser is closing: sid:%v tid:%v",
ev.SessionID, ev.TargetInfo.TargetID,
)
if closeErr := p.Close(); closeErr != nil {
b.logger.Debugf(
"Browser:onAttachedToTarget",
"closing rejected page: %v", closeErr,
)
}
detachSession(session)
return nil
}View on GitHub (pinned to 3fcf5388d7)