-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathscreenshot.js
More file actions
71 lines (55 loc) · 1.54 KB
/
screenshot.js
File metadata and controls
71 lines (55 loc) · 1.54 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const puppeteer = require('puppeteer');
function sleep(ms) {
ms = (ms) ? ms : 0;
return new Promise(resolve => {
setTimeout(resolve, ms);
});
}
process.on('uncaughtException', (error) => {
console.error(error);
process.exit(1);
});
process.on('unhandledRejection', (reason, p) => {
console.error(reason, p);
process.exit(1);
});
const url = process.argv[1];
const filename = process.argv[2];
const width = 1920;
const height = 1080;
const delay = 1000;
const isMobile = false;
(async () => {
const browser = await puppeteer.launch({
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--disable-web-security'
]
});
const page = await browser.newPage();
page.setViewport({
width,
height,
isMobile
});
await page.goto(url, {waitUntil: 'networkidle2'});
// Fix Some URLs to be relative not absolute
await page.evaluate(() => {
items = document.querySelectorAll('img');
items.forEach((item) => {
item.src = item.src.replace('file:///', './');
});
items = document.querySelectorAll('link');
items.forEach((item) => {
item.href = item.href.replace('file:///', './');
});
items = document.querySelectorAll('script');
items.forEach((item) => {
item.src = item.src.replace('file:///', './');
});
})
await sleep(delay);
await page.screenshot({path: filename, fullPage: false});
browser.close();
})();