{"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":1329,"sourceCode":"\t\tWithScreenWidth(screen.Width).\n\t\tWithScreenHeight(screen.Height)\n\tif err := action.Do(cdp.WithExecutor(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(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":1311,"sourceCodeEnd":1347,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/frame_session.go#L1311-L1347","documentation":"Wrap of the CDP Browser.setWindowBounds command: after applying device-metrics emulation, updateViewport recalculates the OS-dependent viewport inset (only when running headed, i.e., hasUIWindow) and resizes the actual browser window to match. This error fires when resizing the window fails — the window ID is stale (window closed), the browser crashed, or the session was canceled during teardown.","triggerScenarios":"Thrown at internal/js/modules/k6/browser/common/frame_session.go:1272 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the browser window still exists when the viewport is updated","Prefer headless mode if window resizing is not essential to the test","Set the viewport at context creation instead of resizing an existing window mid-test","Retry on a new page if the browser session has been torn down"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee","analyzedAt":"2026-09-20T22:01:45.163Z","contentChangedAt":"2026-09-20T22:01:45.163Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}