-
Notifications
You must be signed in to change notification settings - Fork 18
/
index.js
30 lines (26 loc) · 782 Bytes
/
index.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
const puppeteer = require('puppeteer-core');
const fs = require('fs');
screenshot('https://example.com').then(() => console.log('screenshot saved'));
async function screenshot(url) {
const browser = await puppeteer.launch({
headless: true,
args: [
"--no-sandbox",
"--disable-gpu",
]
});
const page = await browser.newPage();
await page.setViewport({width: 1920, height: 1080});
await page.goto(url, {
timeout: 0,
waitUntil: 'networkidle0',
});
const screenData = await page.screenshot({encoding: 'binary', type: 'jpeg', quality: 100});
if (!!screenData) {
fs.writeFileSync('screenshots/screenshot.jpg', screenData);
} else {
throw Error('Unable to take screenshot');
}
await page.close();
await browser.close();
}