{"record":{"id":"063039728b5fde10","repo":"grafana/k6","slug":"enabling-page-lifecycle-events-w","errorCode":null,"errorMessage":"enabling page lifecycle events: %w","messagePattern":"enabling page lifecycle events: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/frame_session.go","lineNumber":456,"sourceCode":"\t\treturn fmt.Errorf(\"got a nil page frame tree\")\n\t}\n\n\t// Any new frame may have a child frame, not just mainframes.\n\tfs.handleFrameTree(frameTree, fs.isMainFrame())\n\n\tif fs.isMainFrame() {\n\t\tfs.initRendererEvents()\n\t}\n\treturn nil\n}\n\nfunc (fs *FrameSession) initIsolatedWorld(name string) error {\n\tfs.logger.Debugf(\"NewFrameSession:initIsolatedWorld\",\n\t\t\"sid:%v tid:%v\", fs.session.ID(), fs.targetID)\n\n\taction := cdppage.SetLifecycleEventsEnabled(true)\n\tif err := action.Do(cdp.WithExecutor(fs.ctx, fs.session)); err != nil {\n\t\treturn fmt.Errorf(\"enabling page lifecycle events: %w\", err)\n\t}\n\n\tif _, ok := fs.isolatedWorlds[name]; ok {\n\t\tfs.logger.Debugf(\"NewFrameSession:initIsolatedWorld\",\n\t\t\t\"sid:%v tid:%v, not found: %q\",\n\t\t\tfs.session.ID(), fs.targetID, name)\n\n\t\treturn nil\n\t}\n\tfs.isolatedWorlds[name] = true\n\n\tvar frames []*Frame\n\tif fs.isMainFrame() {\n\t\tframes = fs.manager.Frames()\n\t} else {\n\t\tframe, ok := fs.manager.getFrameByID(cdp.FrameID(fs.targetID))\n\t\tif ok {\n\t\t\tframes = []*Frame{frame}","sourceCodeStart":438,"sourceCodeEnd":474,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/frame_session.go#L438-L474","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  frame.waitForSelector(sel);\n} catch (e) {\n  if (/enabling page lifecycle events/i.test(String(e))) {\n    // target invalidated between world creation and this CDP call — re-run after page settles\n  }\n}","preventionTips":["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"],"tags":["browser","cdp","lifecycle-events","isolated-world","transient"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}