Skip to content

Instantly share code, notes, and snippets.

@worldofchris
Created May 24, 2020 13:32
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 worldofchris/97e73da954bb0c9c9ffa5287b94ab16b to your computer and use it in GitHub Desktop.
Save worldofchris/97e73da954bb0c9c9ffa5287b94ab16b to your computer and use it in GitHub Desktop.
Grab screenshots of headless chrome browser window
const puppeteer = require('puppeteer');
let _browser;
let _page;
async function please_wait() {
console.log('you wait')
let you_wait = new Promise((resolve, reject) => {
setTimeout( function() {
console.log('time passes');
resolve("Success!")
}, 1000)
})
return you_wait
}
async function run() {
const browser = await puppeteer.launch({dumpio: true, args: [
'--headless', '--use-gl=desktop', "--proxy-server='direct://'", "--proxy-bypass-list=*"
]})
const page = await browser.newPage()
await page.setViewport({
width: 1920,
height: 1080,
deviceScaleFactor: 1,
});
await page.goto('http://127.0.0.1:8080/index.html')
for (var i=0; i < 10000; i++) {
await please_wait()
console.log('taking screenshot')
var num = ('0000'+ i).slice(-4);
await page.screenshot({ path: 'public/screenshot'+ num + '.png' })
}
browser.close();
}
run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment