Right now if I take a screenshot of a page in let's say 1920x1080 pixels, that's the image that it outputs.
Woudln't it be possible to resize the image and get exactly the same screenshot but in a smaller size without having to resize the viewport for the screeenshot?
I want a viewport of 1920x1080 but a screenshot of only 400px width.
I was not able to see any options within the screenshot method: https://github.com/puppeteer/puppeteer/blob/master/docs/api.md#pagescreenshotoptions
Even than the question is too old, I ran into the same issue and might be worth to mention the solution that I have used.
You can use deviceScaleFactor with smaller values than 1.
The quality of the screenshot might not be as good as using libraries such as sharp but for some purposes might be enough.
So for your case if if you scale down by 0.25 you should get and screenshot 480px wide while still rendering a viewport of 1920px
page.setViewport({
width: 1920,
height: 1080,
deviceScaleFactor: 0.25,
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With