Created
July 16, 2018 15:43
-
-
Save frankinedinburgh/89d4f653e05698bcde069687df1d15c9 to your computer and use it in GitHub Desktop.
take a web screenshot using node puppeteer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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