forked from edwardkenfox/reg-suit-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
capture.js
33 lines (27 loc) · 930 Bytes
/
capture.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/* capture.js */
const puppeteer = require('puppeteer');
const mkdirp = require('mkdirp');
const fs = require('fs')
const { URL } = require('url')
async function main() {
const browser = await puppeteer.launch({ args: ['--no-sandbox', '--disable-setuid-sandbox'] });
const json = fs.readFileSync('./screenshots.json')
const rawUrls = JSON.parse(json)["screenshot_urls"]
const urls = rawUrls.map(url => new URL(url))
await (
new Promise(resolve => {
urls.map(async url => {
let page = await browser.newPage();
await page.setViewport({ width: 1280, height: 1080 });
await page.goto(url.href);
await new Promise(res => setTimeout(() => res(), 300));
await page.screenshot({ path: `screenshot/${url.pathname.replace(/\//g, '_')}.png` });
await page.close();
})
resolve();
})
)();
await browser.close();
}
mkdirp.sync('screenshot');
main();