Puppeteer: 'width' in 'clip' must be positive.
Screenshot clip width is zero or negative.
Screenshot clip width is zero or negative.
Error message
'width' in 'clip' must be positive.
How this error happens
A screenshot rectangle must have a positive width. A zero-sized region contains no image to capture.
The snippets use an open Puppeteer page named page.
await page.screenshot({
clip: {
x: 0,
y: 0,
width: 0,
height: 480,
},
});
How to fix
Use a positive width and validate calculated dimensions before passing them to Puppeteer.
await page.screenshot({
clip: {
x: 0,
y: 0,
width: 640,
height: 480,
},
});
Things to keep in mind
If the dimensions come from an element, wait for its layout rather than substituting an arbitrary size.