-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
54 lines (39 loc) · 1.18 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
54
const puppeteer = require('puppeteer');
const takescreenshot = async (url , path) => {
// Launching a new browser instance
const browser = await puppeteer.launch();
// Opening a new page . simply like new tab
const tab = await browser.newPage();
// Setting a view port to desktop
tab.setViewport({
width: 1366,
height: 768
});
// go to the destinated web page
await tab.goto(url);
// get page title
let pagetitle = await tab.title();
// take a screenshot of page
await tab.screenshot( {
path: path + '/' + pagetitle.replace(' ','') + '-Desktop-1366X786.png'
} );
// Set tab viewport sizes
tab.setViewport({
width: 768,
height: 1024
});
await tab.screenshot( {
path: path + '/' + pagetitle.replace(' ','') + '-Tab-768X1024.png'
});
// Set mobile sizes
tab.setViewport({
width: 480,
height: 800
});
await tab.screenshot({
path: path + '/' + pagetitle.replace(' ','') + '-Phone-480X800.png'
});
// Close the browser after all operations
await browser.close();
}
takescreenshot( process.argv[2] , process.argv[3] );