{"record":{"id":"4a0412b1191b7c72","repo":"grafana/k6","slug":"trimming-clip-to-size-w","errorCode":null,"errorMessage":"trimming clip to size: %w","messagePattern":"trimming clip to size: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/screenshotter.go","lineNumber":417,"sourceCode":"\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}\n\t\t}\n\n\t\treturn s.screenshot(p.session, documentRect, nil, format, opts.OmitBackground, opts.Quality, opts.Path)\n\t}\n\n\tviewportRect := &Rect{\n\t\tX:      0,\n\t\tY:      0,\n\t\tWidth:  viewportSize.Width,\n\t\tHeight: viewportSize.Height,\n\t}\n\tif opts.Clip != nil {\n\t\tviewportRect, err = s.trimClipToSize(&Rect{\n\t\t\tX:      opts.Clip.X,\n\t\t\tY:      opts.Clip.Y,\n\t\t\tWidth:  opts.Clip.Width,\n\t\t\tHeight: opts.Clip.Height,","sourceCodeStart":399,"sourceCodeEnd":435,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/screenshotter.go#L399-L435","documentation":"Raised in screenshotPage during a full-page screenshot with a user-supplied clip: the clip rectangle (opts.Clip) must be clamped to the document rect (the full page size) before capture. trimClipToSize returns an error when the clipping math is invalid — i.e. the requested clip lies entirely outside the document bounds or produces a non-positive width/height after clamping. The input at fault is the clip {x, y, width, height} passed in the screenshot options.","triggerScenarios":"Thrown at internal/js/modules/k6/browser/common/screenshotter.go:400 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check that clip x/y/width/height are within the actual page dimensions","Use non-negative, non-zero width and height values for the clip","Measure the page or element bounding box first and derive the clip from it","Omit clip and use fullPage alone if clipping is not strictly required"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}