Skip to content

Instantly share code, notes, and snippets.

@frankinedinburgh
Created July 16, 2018 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frankinedinburgh/89d4f653e05698bcde069687df1d15c9 to your computer and use it in GitHub Desktop.
Save frankinedinburgh/89d4f653e05698bcde069687df1d15c9 to your computer and use it in GitHub Desktop.
take a web screenshot using node puppeteer
const puppeteer = require('puppeteer');
const site = process.argv[2];
async function getPic() {
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
await page.goto(site, {waitUntil: 'networkidle2'});
// Get the "viewport" of the page, as reported by the page.
const dimensions = await page.evaluate(() => {
return {
width: document.documentElement.clientWidth,
height: document.documentElement.clientHeight,
deviceScaleFactor: window.devicePixelRatio
};
});
console.log('Dimensions:', dimensions);
await page.setViewport({width: dimensions.width, height: dimensions.height})
await page.screenshot({path: 'v2.png'});
await browser.close();
}
getPic();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment