-
Notifications
You must be signed in to change notification settings - Fork 0
/
Signer.js
58 lines (44 loc) · 1.27 KB
/
Signer.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
const puppeteer = require("puppeteer-extra");
const pluginStealth = require("puppeteer-extra-plugin-stealth");
puppeteer.use(pluginStealth());
class Signer {
userAgent =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36";
args = [
"--no-sandbox",
"--disable-setuid-sandbox",
"--disable-infobars",
"--window-position=0,0",
"--ignore-certifcate-errors",
"--ignore-certifcate-errors-spki-list",
"--host-rules=MAP tiktok.com 127.0.0.1"
];
constructor() {
this.args.push(`--user-agent="${this.userAgent}"`);
this.options = {
args: this.args,
headless: true,
ignoreHTTPSErrors: true,
userDataDir: "./tmp"
};
}
async init() {
this.browser = await puppeteer.launch(this.options);
this.page = await this.browser.newPage();
await this.page.setUserAgent(this.userAgent);
await this.page.goto("http://tiktok.com:8080/index.html", {
waitUntil: "load"
});
return this;
}
async sign(str) {
let res = await this.page.evaluate(`generateSignature("${str}")`);
return res;
}
async close() {
await this.browser.close();
this.browser = null;
this.page = null;
}
}
module.exports = Signer;