{"record":{"id":"e13e1115ea2d2ba3","repo":"jackwener/OpenCLI","slug":"cdp-screenshot-failed-no-image-data-was-returned","errorCode":null,"errorMessage":"CDP screenshot failed: no image data was returned.","messagePattern":"CDP screenshot failed: no image data was returned\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"clis/uiverse/preview.js","lineNumber":47,"sourceCode":"    const located = await locatePreviewElement(page, payload.html);\n    const rect = located.best.rect;\n    const padding = Math.max(0, Number(kwargs.padding ?? 8));\n    const clip = {\n      x: Math.max(0, rect.x - padding),\n      y: Math.max(0, rect.y - padding),\n      width: Math.max(1, rect.width + padding * 2),\n      height: Math.max(1, rect.height + padding * 2),\n      scale: 1,\n    };\n\n    const shot = await page.cdp('Page.captureScreenshot', {\n      format: 'png',\n      clip,\n      captureBeyondViewport: false,\n    });\n    const base64 = typeof shot === 'string' ? shot : shot?.data;\n    if (!base64) {\n      throw new Error('CDP screenshot failed: no image data was returned.');\n    }\n\n    const outputPath = kwargs.output || getDefaultOutputPath({\n      username: detail.username,\n      slug: detail.slug,\n      suffix: 'preview',\n      extension: 'png',\n    });\n    const savedPath = await saveBase64File(base64, outputPath);\n\n    return {\n      username: detail.username,\n      slug: detail.slug,\n      url: detail.url,\n      output: savedPath,\n      width: Math.round(clip.width),\n      height: Math.round(clip.height),\n      x: Math.round(clip.x),","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/uiverse/preview.js#L29-L65","documentation":"This error is thrown by the uiverse preview CLI when a Chrome DevTools Protocol (CDP) screenshot call completes but returns no image payload. The code accepts either a base64 string or an object with a `.data` field; if neither is present it cannot build the PNG file, so it fails fast with this message rather than writing an empty/corrupt file.","triggerScenarios":"Calling the uiverse preview command: Page.captureScreenshot (via CDP with format 'png', a clip rect, and captureBeyondViewport:false) resolves to null/undefined or an object lacking `.data` — typically when the target page/tab crashed or was closed mid-capture, the clip rect is invalid (zero/negative size or off-screen), or the browser returned an empty response.","commonSituations":"Headless browser tab navigated away or crashed during capture; clip computed from an element with zero dimensions because the component failed to render; older Chrome/CDP versions returning a different response shape; CDP session detached right before the screenshot call.","solutions":["Re-run the command; transient tab/crash issues often resolve on retry.","Verify the target component renders and has non-zero size (a zero-width/height clip can make CDP return no data).","Update Chrome/Chromium and any CDP driver so captureScreenshot returns the expected {data} object.","Log the raw `shot` value before the check to see what shape the browser actually returns and adapt extraction.","Use a fresh browser instance/profile if the previous tab was in a crashed state."],"exampleFix":"// before\nconst base64 = typeof shot === 'string' ? shot : shot?.data;\nif (!base64) {\n  throw new Error('CDP screenshot failed: no image data was returned.');\n}\n// after\nconst base64 = typeof shot === 'string' ? shot : shot?.data;\nif (!base64) {\n  await page.reload();            // recover from a stale/crashed tab\n  shot = await client.send('Page.captureScreenshot', { format: 'png', clip, captureBeyondViewport: false });\n}\nif (!base64) throw new Error('CDP screenshot failed: no image data was returned.');","handlingStrategy":"retry","validationCode":"const clip = { x: el.offsetLeft, y: el.offsetTop, width: el.offsetWidth, height: el.offsetHeight };\nif (!(clip.width > 0 && clip.height > 0)) throw new Error('Element has zero size; cannot screenshot');","typeGuard":"function hasImageData(shot) {\n  return typeof shot === 'string' && shot.length > 0 ||\n         (shot && typeof shot === 'object' && typeof shot.data === 'string' && shot.data.length > 0);\n}","tryCatchPattern":"try {\n  let shot = await client.send('Page.captureScreenshot', { format: 'png', clip, captureBeyondViewport: false });\n  if (!hasImageData(shot)) throw new Error('transient-empty-screenshot');\n} catch (e) {\n  if (e.message === 'transient-empty-screenshot') { await page.reload(); /* retry once */ }\n  else throw e;\n}","preventionTips":["Ensure the clip target has non-zero dimensions before capturing.","Retry the capture once on empty results — tab crashes are often transient.","Keep Chrome/CDP driver versions current so captureScreenshot returns the documented {data} shape.","Log the raw screenshot response when debugging rather than assuming its shape."],"tags":["cdp","screenshot","browser-automation"],"backgroundTag":"cdp-screenshot-empty-response","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}