forked from styleguidist/react-styleguidist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrowser.js
35 lines (26 loc) · 847 Bytes
/
browser.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
34
35
/* eslint-disable no-console */
/* eslint-disable import/no-extraneous-dependencies */
/* eslint-disable import/no-unresolved */
const puppeteer = require('puppeteer');
const path = require('path');
const args = process.argv.slice(2);
let browser;
async function onerror(err) {
console.error(err.stack);
await browser.close();
process.exit(1);
}
(async () => {
browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setViewport({ width: 1024, height: 768 });
page.on('error', onerror);
page.on('pageerror', onerror);
page.on('console', (...args) => console.log('PAGE LOG:', ...args));
const url = /https?/.test(args[0]) ? args[0] : `file://${path.resolve(args[0])}`;
await page.goto(url);
if (args[1]) {
await page.screenshot({ path: args[1] });
}
await browser.close();
})().catch(onerror);