Created
November 27, 2018 22:09
-
-
Save 5shekel/847c3040ffd37328367bf3df206058f1 to your computer and use it in GitHub Desktop.
//grab a screenshot using chromedriver headless
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
//grab a screenshot using chromedriver headless | |
//see install of pupetter on | |
//https://pptr.dev/ | |
const puppeteer = require('puppeteer'); | |
// print process.argv | |
console.log(process.argv.length); | |
if (process.argv.length <= 2) { | |
console.log("Usage: " + __filename + " URL and IMAGE.jpg"); | |
process.exit(-1); | |
} | |
process.argv.forEach(function (val, index, array) { | |
console.log(index + ': ' + val); | |
}); | |
(async () => { | |
//follow the readme and enable sandbox on your kernel | |
const browser = await puppeteer.launch(); | |
//also possible to run without sandbox, like this | |
/// ...pupeteer.launch({args: ['--no-sandbox','--disable-setuid-sandbox']}); | |
const page = await browser.newPage(); | |
await page.goto(process.argv[2]); | |
await page.screenshot({path: process.argv[3]}); | |
await browser.close(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment