Let's talk about the fromSurface parameter introduced in Chrome DevTools Protocol which will soon be supported by Puppeteer or even supported now at the time when you are reading the post.
Take a screenshot "from the surface" in Puppeteer and Chrome DevTools Protocol
Let's talk about the fromSurface parameter introduced in Chrome DevTools Protocol which will soon be supported by Puppeteer or even supported now at the time when you are reading the post.
When fromSurface
is set to true
, captures screenshot from the surface rather than the view. When it is set to false
, works only in headful mode and ignores page viewport (but not browser window’s bounds). Defaults to true
.
The option doesn’t make much sense when using headless mode. But to understand how it works, let’s execute the next code in the headful mode:
'use strict';
const puppeteer = require('puppeteer');(async () => { const browser = await puppeteer.launch({headless: false}); try { const page = await browser.newPage(); await page.setViewport({width: 1920, height: 1280});
await page.goto('https://screenshotone.com');
await page.screenshot({ path: 'from_surface_false.png', fromSurface: false}); } catch (e) { console.log(e) } finally { await browser.close(); }})();
The window is opened, and it is size is limited by the default window size, but the viewport size is different, so that’s what you would see if you run the code:
So, when fromSurface
is set to false
, that’s how the screenshot will look like:
By the way, there is a few related articles you might be interested in:
Interviews, tips, guides, industry best practices, and news.
We can consider the screenshot of URL or HTML as a thumbnail, but I write about the thumbnail of a screenshot. How do you take a screenshot within the defined viewport but with different image width and height? Resize!
A few words about why to launch yet another website screenshotting tool.
It is a good milestone to make a compact snapshot of the insights that (maybe?) led to it.
Exhaustive documentation, ready SDKs, no-code tools, and other automation to help you render website screenshots and outsource all the boring work related to that to us.