{"record":{"id":"358db0b40c110b6f","repo":"grafana/k6","slug":"restoring-viewport-to-s-w","errorCode":null,"errorMessage":"restoring viewport to %s: %w","messagePattern":"restoring viewport to (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/screenshotter.go","lineNumber":400,"sourceCode":"\t}\n\toriginalSize := p.emulatedSize\n\n\tif opts.FullPage { //nolint:nestif\n\t\tfullPageSize, sizeErr := s.fullPageSize(p)\n\t\tif sizeErr != nil {\n\t\t\treturn nil, fmt.Errorf(\"getting full page size: %w\", sizeErr)\n\t\t}\n\t\tdocumentRect := &Rect{\n\t\t\tX:      0,\n\t\t\tY:      0,\n\t\t\tWidth:  fullPageSize.Width,\n\t\t\tHeight: fullPageSize.Height,\n\t\t}\n\t\tfitsViewport := fullPageSize.Width <= viewportSize.Width && fullPageSize.Height <= viewportSize.Height\n\t\tif !fitsViewport {\n\t\t\tdefer func() {\n\t\t\t\tif restoreErr := s.restoreViewport(p, originalSize); restoreErr != nil {\n\t\t\t\t\terr = errors.Join(err, fmt.Errorf(\"restoring viewport to %s: %w\",\n\t\t\t\t\t\tviewportSize, restoreErr))\n\t\t\t\t}\n\t\t\t}()\n\t\t\tif err := p.setViewportSize(s.ctx, fullPageSize); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"setting viewport size to %s: %w\",\n\t\t\t\t\tfullPageSize, err)\n\t\t\t}\n\t\t}\n\t\tif opts.Clip != nil {\n\t\t\tdocumentRect, err = s.trimClipToSize(&Rect{\n\t\t\t\tX:      opts.Clip.X,\n\t\t\t\tY:      opts.Clip.Y,\n\t\t\t\tWidth:  opts.Clip.Width,\n\t\t\t\tHeight: opts.Clip.Height,\n\t\t\t}, &Size{Width: documentRect.Width, Height: documentRect.Height})\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"trimming clip to size: %w\", err)\n\t\t\t}","sourceCodeStart":382,"sourceCodeEnd":418,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/screenshotter.go#L382-L418","documentation":"Raised at the end of screenshotPage when a full-page screenshot required enlarging the viewport (overriddenViewportSize != nil) and restoring the original viewport via restoreViewport fails. The '%s' is the original viewport size being restored. This is a cleanup-path failure: the screenshot bytes were already captured but the CDP call to reset the device metrics override was rejected, commonly because the page or CDP session closed mid-operation, so the error replaces the successful result.","triggerScenarios":"Thrown at internal/js/modules/k6/browser/common/screenshotter.go:410 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Keep the page and browser alive until the screenshot call fully completes","Retry the screenshot on a healthy page/session","Avoid extremely large full-page captures that stress the target during viewport restore","Check the wrapped CDP error for the precise override-reset failure"],"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"}