-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
executable file
·53 lines (46 loc) · 1.39 KB
/
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env node
const puppeteer = require('puppeteer');
const argv = require('yargs').argv
require('yargs') // eslint-disable-line
.usage('Usage: $0 screenshot [url] [image]')
.command('screenshot [url] [image]', 'Take screenshot from URL to image file', (yargs) => {
yargs
.positional('url', {
describe: 'URL to take screenshot from',
default: 'https://example.com',
})
.positional('image', {
describe: 'Path to write image file to',
default: './screenshot.png',
})
}, (argv) => {
console.warn('Taking screenshot from ' + argv.url + ' to ' + argv.image + '...');
return takeScreenshot(argv.url, argv.image)
.then(() => {
console.warn('Done.');
});
})
.argv;
async function takeScreenshot(url, image) {
const chromiumBinPath = '/usr/bin/chromium-browser';
const browser = await puppeteer.launch({
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--disable-dev-shm-usage',
'--single-process',
'--ignore-certificate-errors',
],
//pipe: true,
ignoreHTTPSErrors: true,
headless: true,
executablePath: chromiumBinPath,
});
const page = await browser.newPage();
await page.goto(url);
await page.screenshot({
path: image,
omitBackground: true
});
await browser.close();
}