{"record":{"id":"d6ff2c24f2b00f2f","repo":"grafana/k6","slug":"emulating-viewport-w","errorCode":null,"errorMessage":"emulating viewport: %w","messagePattern":"emulating viewport: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/frame_session.go","lineNumber":1314,"sourceCode":"\t\treturn nil\n\t}\n\tviewport := emulatedSize.Viewport\n\tscreen := emulatedSize.Screen\n\n\torientation := emulation.ScreenOrientation{\n\t\tAngle: 0.0,\n\t\tType:  emulation.OrientationTypePortraitPrimary,\n\t}\n\tif viewport.Width > viewport.Height {\n\t\torientation.Angle = 90.0\n\t\torientation.Type = emulation.OrientationTypeLandscapePrimary\n\t}\n\taction := emulation.SetDeviceMetricsOverride(viewport.Width, viewport.Height, opts.DeviceScaleFactor, opts.IsMobile).\n\t\tWithScreenOrientation(&orientation).\n\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","sourceCodeStart":1296,"sourceCodeEnd":1332,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/frame_session.go#L1296-L1332","documentation":"Wrap of the CDP Emulation.setDeviceMetricsOverride command: updateViewport computes the emulated viewport and screen size, picks a portrait/landscape orientation from the dimensions, and sends the override (width, height, deviceScaleFactor, isMobile, screen orientation/size) to the main-frame session. The wrapped error occurs when the CDP call fails — closed/canceled context, detached session, or dimensions/scale factor values the browser rejects (e.g., zero width/height).","triggerScenarios":"Thrown at internal/js/modules/k6/browser/common/frame_session.go:1257 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Provide a valid Viewport with positive width and height","Ensure the page and its main-frame session are still alive when changing the viewport","Avoid changing viewport size while the target is navigating or closing","Retry with a fresh page if the browser session was terminated"],"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"}