-
Notifications
You must be signed in to change notification settings - Fork 0
/
ppt.js
61 lines (53 loc) · 1.44 KB
/
ppt.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
55
56
57
58
59
60
61
const puppeteer = require('puppeteer');
const { msg } = require('./msg');
class ppt {
/** @type {puppeteer.Page} */
page;
/** @type {puppeteer.Browser} */
browser;
get = async () => {
const debug = true;
if (debug) {
this.browser = await puppeteer.launch({
// headless: false,
defaultViewport: null,
args: ['--start-maximized'],
});
this.page = await this.browser.newPage();
await this.page.setJavaScriptEnabled(false);
} else {
const browser = await puppeteer.launch({
// headless: false,
defaultViewport: null,
args: ['--start-maximized'],
});
this.page = await this.browser.newPage();
await this.page.setDefaultTimeout(120 * 1000);
await this.page.setJavaScriptEnabled(false);
await this.page.setViewport({
width: 1366,
height: 768,
});
}
};
/** @param {String} url */
async goto(url, waitUntil = 'networkidle0') {
try {
msg.substep(`goto ${url}`);
await this.page.goto(url, { waitUntil });
} catch (error) {
msg.die(`goto ${selector} error waitUntil ${waitUntil} `);
}
}
/** @param {String} selector */
async waitForSelector(selector, timeout = 5000) {
try {
msg.substep(`waitForSelector ${selector}`);
await this.page.waitForSelector(selector, { timeout });
} catch (error) {
msg.error(`selector ${selector} not found timeout ${timeout} `);
throw new Error(`selector ${selector} not found timeout ${timeout} `);
}
}
}
module.exports = { ppt };