-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmodule.js
More file actions
26 lines (21 loc) · 883 Bytes
/
module.js
File metadata and controls
26 lines (21 loc) · 883 Bytes
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
import puppeteer from 'puppeteer';
import {deleteAsync} from 'del';
import fs from 'fs';
const screenshot_path = './screenshots/';
export const sleep = (milliseconds) => {
return new Promise(resolve => setTimeout(resolve, milliseconds));
}
export async function clear() {
await deleteAsync([`${screenshot_path}`]);
if (!fs.existsSync(screenshot_path)) fs.mkdirSync(screenshot_path);
fs.appendFileSync(screenshot_path + '.gitkeep', '');
}
export async function openbrowser (name, url, width, height, ext = 'png', sleeptime = 1000) {
const browser = await puppeteer.launch({ headless: false, defaultViewport: {width:width, height:height} });
const page = await browser.newPage();
await page.goto(url);
await sleep(sleeptime);
await page.screenshot({path: screenshot_path + name + '.' + ext});
browser.close();
}
export default openbrowser;