-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
browser.js
44 lines (41 loc) · 1.67 KB
/
browser.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
const puppeteer = require("puppeteer-extra");
puppeteer.use(require("puppeteer-extra-plugin-stealth")());
class Browser {
async browser () {
this.browser = await puppeteer.launch({"headless": false, userDataDir: "Data"});
this.page = await this.browser.newPage();
await this.page.setViewport({"width": 1920, "height": 1080});
await this.page.setBypassCSP(true);
await this.page.setDefaultTimeout(30000);
await this.page.setRequestInterception(true);
await this.page.on("request", (req) => {
if (req.resourceType() === "image" ||
req.resourceType() === "stylesheet" ||
req.resourceType() === "font" ||
req.resourceType() === "beacon" ||
req.resourceType() === "csp_report" ||
req.resourceType() === "imageset" ||
req.resourceType() === "media" ||
req.resourceType() === "object" ||
req.resourceType() === "object_subrequest" ||
req.resourceType() === "ping" ||
req.resourceType() === "script" ||
req.resourceType() === "speculative" ||
req.resourceType() === "sub_frame" ||
req.resourceType() === "web_manifest" ||
req.resourceType() === "websocket" ||
req.resourceType() === "xml_dtd" ||
req.resourceType() === "xmlhttprequest" ||
req.resourceType() === "xslt" ||
req.resourceType() === "other") {
req.abort();
} else {
req.continue();
}
});
}
async close () {
this.browser.close();
}
}
module.exports = Browser;