{"record":{"id":"838608cf0152f625","repo":"grafana/k6","slug":"setting-window-bounds-w","errorCode":null,"errorMessage":"setting window bounds: %w","messagePattern":"setting window bounds: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/frame_session.go","lineNumber":1272,"sourceCode":"\t\tWithScreenWidth(screen.Width).\n\t\tWithScreenHeight(screen.Height)\n\tif err := action.Do(cdp.WithExecutor(fs.ctx, fs.session)); err != nil {\n\t\treturn fmt.Errorf(\"emulating viewport: %w\", err)\n\t}\n\n\tif fs.hasUIWindow {\n\t\t// add an inset to viewport depending on the operating system.\n\t\t// this won't add an inset if we're running in headless mode.\n\t\tviewport = viewport.recalculateInset(\n\t\t\tfs.page.browserCtx.browser.browserOpts.Headless,\n\t\t\truntime.GOOS,\n\t\t)\n\t\taction2 := browser.SetWindowBounds(fs.windowID, &browser.Bounds{\n\t\t\tWidth:  viewport.Width,\n\t\t\tHeight: viewport.Height,\n\t\t})\n\t\tif err := action2.Do(cdp.WithExecutor(fs.ctx, fs.session)); err != nil {\n\t\t\treturn fmt.Errorf(\"setting window bounds: %w\", err)\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc (fs *FrameSession) executionContextForID(\n\texecutionContextID cdpruntime.ExecutionContextID,\n) (*ExecutionContext, error) {\n\tfs.contextIDToContextMu.Lock()\n\tdefer fs.contextIDToContextMu.Unlock()\n\n\tif exc, ok := fs.contextIDToContext[executionContextID]; ok {\n\t\treturn exc, nil\n\t}\n\n\treturn nil, fmt.Errorf(\"no execution context found for id: %v\", executionContextID)\n}","sourceCodeStart":1254,"sourceCodeEnd":1290,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/frame_session.go#L1254-L1290","documentation":"Only in headed mode (hasUIWindow), after viewport emulation k6 resizes the actual OS window with Browser.setWindowBounds so the visible window matches the emulated viewport plus OS-specific insets. This error means that window-resize command failed. In headless mode this code path is skipped entirely.","triggerScenarios":"Running with headless: false together with a viewport option; the window ID became invalid (window closed between page creation and resize), the window is minimized/fullscreen so it cannot be resized, or the DevTools connection dropped before the command was executed.","commonSituations":"Local headed debugging with an explicit viewport; CI jobs accidentally running headed without a display server or window manager; desktop environments denying programmatic resize; closing the window manually mid-test.","solutions":["Run headless in CI, or provide a real display/xvfb when headed mode is required","Do not close or minimize the window between page creation and viewport application","Retry once; if the emulated viewport already applied, the window bounds step is cosmetic and a retry usually succeeds","Upgrade k6: window bounds and inset handling have improved across releases"],"exampleFix":"// before: headed CI without display\nconst browser = chromium.launch({ headless: false });\nconst page = await browser.newPage({ viewport: { width: 1280, height: 720 } });\n\n// after: headless for CI\nconst browser = chromium.launch({ headless: true });\nconst page = await browser.newPage({ viewport: { width: 1280, height: 720 } });","handlingStrategy":"validation","validationCode":"// avoid the headed window-resize path entirely in CI\nconst headless = __ENV.CI === 'true';\nconst browser = chromium.launch({ headless });","typeGuard":null,"tryCatchPattern":"try { await page.setViewport(...); }\ncatch (e) { if (!/setting window bounds/.test(String(e.message))) throw e; /* retry or continue */ }","preventionTips":["Run headless unless you explicitly need a visible window","For headed runs, provide a real display or xvfb","Do not minimize or close the window between page creation and viewport application"],"tags":["browser","headed-mode","viewport","cdp","window-management"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}