{"record":{"id":"fa4ef2bb27e3f43f","repo":"grafana/k6","slug":"getting-browser-window-id-w","errorCode":null,"errorMessage":"getting browser window ID: %w","messagePattern":"getting browser window ID: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/frame_session.go","lineNumber":155,"sourceCode":"\tif err != nil {\n\t\tl.Debugf(\"NewFrameSession:NewNetworkManager\", \"sid:%v tid:%v err:%v\",\n\t\t\ts.ID(), tid, err)\n\t\treturn nil, err\n\t}\n\n\t// When a frame creates a new FrameSession without UI (e.g. some iframes) we cannot\n\t// retrieve the windowID. Doing so would lead to an error from chromium. For now all\n\t// iframes that are attached are setup with hasUIWindow as false which seems to work\n\t// as expected for iframes with and without UI elements.\n\tif fs.hasUIWindow {\n\t\taction := browser.GetWindowForTarget().WithTargetID(fs.targetID)\n\t\tif fs.windowID, _, err = action.Do(cdp.WithExecutor(fs.ctx, fs.session)); err != nil {\n\t\t\tl.Debugf(\n\t\t\t\t\"NewFrameSession:GetWindowForTarget\",\n\t\t\t\t\"sid:%v tid:%v err:%v\",\n\t\t\t\ts.ID(), tid, err)\n\n\t\t\treturn nil, fmt.Errorf(\"getting browser window ID: %w\", err)\n\t\t}\n\t}\n\n\tfs.initEvents()\n\tif err = fs.initFrameTree(); err != nil {\n\t\tl.Debugf(\n\t\t\t\"NewFrameSession:initFrameTree\",\n\t\t\t\"sid:%v tid:%v err:%v\",\n\t\t\ts.ID(), tid, err)\n\n\t\treturn nil, err\n\t}\n\tif err = fs.initIsolatedWorld(utilityWorldName); err != nil {\n\t\tl.Debugf(\n\t\t\t\"NewFrameSession:initIsolatedWorld\",\n\t\t\t\"sid:%v tid:%v err:%v\",\n\t\t\ts.ID(), tid, err)\n","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/frame_session.go#L137-L173","documentation":"For frame sessions with a UI window (main frames, not iframes), NewFrameSession calls Browser.getWindowForTarget (frame_session.go:155) to record the window ID. If that CDP command fails, session creation aborts with this wrapped error. It indicates the target/window no longer exists from chromium's perspective, or the CDP session is broken.","triggerScenarios":"Creating or navigating a page whose window is destroyed concurrently (window.close(), browser shutdown), chromium crashing during page setup, or headed mode in an environment without a display/Wayland-X11 issues.","commonSituations":"Scripts that open and rapidly close pages under load, Xvfb/display misconfiguration for headed chromium in CI, and remote-browser setups where the target is closed between attach and this call.","solutions":["Ensure pages are not being closed concurrently while they initialize; sequence page creation and close() in the same VU","For headed mode in CI, provide a display (xvfb-run) or use K6_BROWSER_HEADLESS=true","If it happens randomly under load, suspect chromium stability/resources (memory limits, zombie processes) and restart the browser between iterations"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const page = browser.newPage();\n} catch (e) {\n  if (/getting browser window ID/i.test(String(e))) {\n    // target/window vanished during init — close context and retry once\n  }\n}","preventionTips":["Never close pages from other VUs or async paths while pages initialize","Use K6_BROWSER_HEADLESS=true in CI or provide a display for headed runs","Restart the browser between iterations for long-running suites"],"tags":["browser","cdp","window","session","infrastructure"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}