Created
March 2, 2018 19:01
-
-
Save gabemarshall/d08728aa85ffe54a26006025f0b23d53 to your computer and use it in GitHub Desktop.
screenshot a website with puppeteer (headless chrome)
This file contains 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 argv = require('yargs').argv | |
if (argv.url && argv.filename){ | |
(async () => { | |
const browser = await puppeteer.launch({headless: true, ignoreHTTPSErrors: true}); | |
process.on("unhandledRejection", (reason, p) => { | |
console.error("Unhandled Rejection at: Promise", p, "reason:", reason); | |
browser.close(); | |
}); | |
const page = await browser.newPage(); | |
page.on('error', function(msg){ | |
console.log(msg); | |
}) | |
page.on('pageerror', function(msg){ | |
console.log(msg); | |
}) | |
await page.goto(argv.url, {timeout: 10000}) | |
await page.waitForSelector('body'); | |
await page.screenshot({path: argv.filename}); | |
await browser.close(); | |
})(); | |
} else { | |
console.log("Try screen --url=https://www.example.com --filename=foo.png"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment