{"record":{"id":"6427a8d503899270","repo":"grafana/k6","slug":"capturing-screenshot-w","errorCode":null,"errorMessage":"capturing screenshot: %w","messagePattern":"capturing screenshot: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/screenshotter.go","lineNumber":221,"sourceCode":"\tscale := 1.0\n\tif viewport != nil {\n\t\tscale = visualViewportScale\n\t}\n\tclip = &cdppage.Viewport{\n\t\tX:      doc.X,\n\t\tY:      doc.Y,\n\t\tWidth:  doc.Width,\n\t\tHeight: doc.Height,\n\t\tScale:  scale,\n\t}\n\tif clip.Width > 0 && clip.Height > 0 {\n\t\tcapture = capture.WithClip(clip)\n\t}\n\n\t// Capture screenshot\n\tbuf, err = capture.Do(cdp.WithExecutor(s.ctx, sess))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"capturing screenshot: %w\", err)\n\t}\n\n\tif shouldSetDefaultBackground {\n\t\taction := emulation.SetDefaultBackgroundColorOverride()\n\t\tif err := action.Do(cdp.WithExecutor(s.ctx, sess)); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"resetting screenshot background color: %w\", err)\n\t\t}\n\t}\n\n\t// Save screenshot capture to file\n\tif path != \"\" {\n\t\tif err := s.persister.Persist(s.ctx, path, bytes.NewBuffer(buf)); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"persisting screenshot: %w\", err)\n\t\t}\n\t}\n\n\treturn buf, nil\n}","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/screenshotter.go#L203-L239","documentation":"The core Page.captureScreenshot CDP command failed. By this point options were validated, the background override (if any) applied and the clip computed — the browser itself refused or failed to produce the image bytes.","triggerScenarios":"Renderer crash ('Aw, Snap' / SIGSEGV in chrome), page or target closed while capturing, GPU/compositing failures in the execution environment, session cancelled by k6 shutdown or iteration timeout, or captures on a tab that was backgrounded/discarded by the OS.","commonSituations":"Very large fullPage screenshots exhausting memory in CI containers (renderer OOM-killed); headless chrome without --disable-gpu or with software rasterizer bugs; screenshot racing page.close(); too many concurrent pages capturing at once.","solutions":["Verify the page is open and stable: await page.goto(url); await page.waitForLoadState('load'); before capturing, and never close concurrently.","Reduce capture cost: avoid fullPage on gigantic pages, lower viewport size, or capture JPEG instead of PNG.","Raise resource limits for the browser process (container memory) or screenshot fewer pages in parallel.","Retry the capture once — renderer crashes are frequently one-off; if persistent, set K6_BROWSER_ARGS/--disable-gpu or switch headless shell version, and report to grafana/k6 if reproducible."],"exampleFix":"// before\nawait page.screenshot({ path: 'big.png', fullPage: true }); // renderer OOM on huge page\n\n// after\nawait page.screenshot({ path: 'big.jpg', fullPage: true, type: 'jpeg', quality: 80 });","handlingStrategy":"retry","validationCode":"if (page.isClosed()) throw new Error('page closed; cannot capture');","typeGuard":null,"tryCatchPattern":"async function shot(p, opts, n = 2) {\n  for (let i = 0; i < n; i++) {\n    try { return await p.screenshot(opts); }\n    catch (e) { if (i === n - 1 || !/capturing screenshot/i.test(String(e))) throw e; await sleep(1000); }\n  }\n}","preventionTips":["Avoid fullPage PNG captures on enormous pages; prefer JPEG.","Give the browser container enough memory.","Keep captures serialized; no close/goto during capture."],"tags":["k6","browser","screenshot","cdp","renderer-crash","memory"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}