-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwebshot.js
40 lines (29 loc) · 1.06 KB
/
webshot.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
36
37
38
39
40
const puppeteer = require('puppeteer');
const url = require('url');
const args = require('minimist')(process.argv.slice(3));
// defaults options
const site = process.argv[2] || "https://ohthatsnice.net";
const zoom = args.zoom || 90;
const delay = args.delay || 0;
const width = args.width || 1200;
const height = args.height || 800;
// create name for image from hostname
const name = url.parse(site.replace('www.', '')).hostname.split('.')[0];
// take the screenshot
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setViewport({
width: width,
height: height
});
await page.goto(site);
await page.waitFor(delay);
// uncomment to remove elements from the page by selector
// await page.$eval('.global-announcement', el => el.remove());
// uncomment to click element on a page by selector
// await page.click('.close-cookie-banner');
await page.evaluate('document.body.style.zoom="'+ zoom + '%";');
await page.screenshot({path: 'shots/' + name + '.png'});
browser.close();
})();