grafana/k6 · error
enabling page lifecycle events: %w
Error message
enabling page lifecycle events: %w
What it means
FrameSession.initIsolatedWorld (frame_session.go:456) begins by sending Page.setLifecycleEventsEnabled(true) so k6 can observe load/domContentLoaded/networkIdle. If the CDP command fails, world initialization aborts with this wrapped error. Failures here are environmental: the target is gone or the CDP session is broken, since this command has no script-controllable parameters.
Source
Thrown at internal/js/modules/k6/browser/common/frame_session.go:456
return fmt.Errorf("got a nil page frame tree")
}
// Any new frame may have a child frame, not just mainframes.
fs.handleFrameTree(frameTree, fs.isMainFrame())
if fs.isMainFrame() {
fs.initRendererEvents()
}
return nil
}
func (fs *FrameSession) initIsolatedWorld(name string) error {
fs.logger.Debugf("NewFrameSession:initIsolatedWorld",
"sid:%v tid:%v", fs.session.ID(), fs.targetID)
action := cdppage.SetLifecycleEventsEnabled(true)
if err := action.Do(cdp.WithExecutor(fs.ctx, fs.session)); err != nil {
return fmt.Errorf("enabling page lifecycle events: %w", err)
}
if _, ok := fs.isolatedWorlds[name]; ok {
fs.logger.Debugf("NewFrameSession:initIsolatedWorld",
"sid:%v tid:%v, not found: %q",
fs.session.ID(), fs.targetID, name)
return nil
}
fs.isolatedWorlds[name] = true
var frames []*Frame
if fs.isMainFrame() {
frames = fs.manager.Frames()
} else {
frame, ok := fs.manager.getFrameByID(cdp.FrameID(fs.targetID))
if ok {
frames = []*Frame{frame}View on GitHub (pinned to 93accf6570)
Solutions
- Perform waits against a stable, fully loaded page (chain after goto with a suitable waitUntil)
- Ensure pages are not closed by the application while k6 is setting up waits
- Reduce per-renderer memory pressure (fewer VUs/pages) if renderer crashes are the root cause
Defensive patterns
Strategy: retry
Try / catch
try {
frame.waitForSelector(sel);
} catch (e) {
if (/enabling page lifecycle events/i.test(String(e))) {
// target invalidated between world creation and this CDP call — re-run after page settles
}
} Prevention
- Issue waits after navigation settles (goto with a suitable waitUntil first)
- Prevent the site from closing the page (block window.close-inducing flows) during waits
When it happens
Trigger: The first waitForSelector/waitForFunction call triggers isolated-world setup; if the page has navigated away, crashed, or been closed in the meantime, this command fails. Also seen when the renderer dies under memory pressure.
Common situations: Calling waitFor* immediately after a navigation that invalidates the context, page closed by site JS (window.close), chromium renderer OOM crashes in long test runs.
Related errors
- adding script to evaluate on new document: %w
- adding k6 object to new browser context: %w
- getting page frame tree: %w
- WebSocket endpoint cannot be empty
- can't fetch the page for unknown reason
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/063039728b5fde10.
Report an issue: GitHub.