puppeteer is a tools created by Google to control the chrome/Chromium browser by script. It is useful for automatic testing website, or use it to control a headless browser. To use puppeteer to capture screenshot of a site, do:
npm i puppeteer
const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.goto("https://www.google.com", {waitUntil: 'networkidle0'}); //await page.waitForTimeout(1000) await page.screenshot({ path: 'example.png' }); await browser.close(); })();
networkidle0
the code will wait 500ms after all network activity is done. If the site has some javascript animation, you might need to wait more by using the commentted out waitForTimeout
code
node example.js
in the terminal.
Add defaultViewport in the code like:
const browser = await puppeteer.launch({ defaultViewport: {width: 1920, height: 1080} });