jackwener/OpenCLI · error · Error
CDP screenshot failed: no image data was returned.
Error message
CDP screenshot failed: no image data was returned.
What it means
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.
Source
Thrown at clis/uiverse/preview.js:47
const located = await locatePreviewElement(page, payload.html);
const rect = located.best.rect;
const padding = Math.max(0, Number(kwargs.padding ?? 8));
const clip = {
x: Math.max(0, rect.x - padding),
y: Math.max(0, rect.y - padding),
width: Math.max(1, rect.width + padding * 2),
height: Math.max(1, rect.height + padding * 2),
scale: 1,
};
const shot = await page.cdp('Page.captureScreenshot', {
format: 'png',
clip,
captureBeyondViewport: false,
});
const base64 = typeof shot === 'string' ? shot : shot?.data;
if (!base64) {
throw new Error('CDP screenshot failed: no image data was returned.');
}
const outputPath = kwargs.output || getDefaultOutputPath({
username: detail.username,
slug: detail.slug,
suffix: 'preview',
extension: 'png',
});
const savedPath = await saveBase64File(base64, outputPath);
return {
username: detail.username,
slug: detail.slug,
url: detail.url,
output: savedPath,
width: Math.round(clip.width),
height: Math.round(clip.height),
x: Math.round(clip.x),View on GitHub (pinned to 49907e53dc)
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.
Example fix
// before
const base64 = typeof shot === 'string' ? shot : shot?.data;
if (!base64) {
throw new Error('CDP screenshot failed: no image data was returned.');
}
// after
const base64 = typeof shot === 'string' ? shot : shot?.data;
if (!base64) {
await page.reload(); // recover from a stale/crashed tab
shot = await client.send('Page.captureScreenshot', { format: 'png', clip, captureBeyondViewport: false });
}
if (!base64) throw new Error('CDP screenshot failed: no image data was returned.'); Defensive patterns
Strategy: retry
Validate before calling
const clip = { x: el.offsetLeft, y: el.offsetTop, width: el.offsetWidth, height: el.offsetHeight };
if (!(clip.width > 0 && clip.height > 0)) throw new Error('Element has zero size; cannot screenshot'); Type guard
function hasImageData(shot) {
return typeof shot === 'string' && shot.length > 0 ||
(shot && typeof shot === 'object' && typeof shot.data === 'string' && shot.data.length > 0);
} Try / catch
try {
let shot = await client.send('Page.captureScreenshot', { format: 'png', clip, captureBeyondViewport: false });
if (!hasImageData(shot)) throw new Error('transient-empty-screenshot');
} catch (e) {
if (e.message === 'transient-empty-screenshot') { await page.reload(); /* retry once */ }
else throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- amazon ${action} navigation lost the current browser target
- ChatGPT model selection requires native browser click suppor
- ChatGPT tool selection requires native browser click support
- Ctrip flight API response body was unavailable
- `Failed to capture GeoGebra screenshot: ${err?.message || er
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/e13e1115ea2d2ba3.
Report an issue: GitHub.