-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathpool.js
47 lines (42 loc) · 1.19 KB
/
pool.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
const genericPool = require('generic-pool');
const puppeteer = require('puppeteer');
const conf = require('./conf');
const { browser, bot, data } = conf.config;
const ARGS = [
`--lang=${browser.lang}`,
`--disable-dev-shm-usage`,
`--no-user-gesture-required`,
`--use-fake-ui-for-media-stream`,
`--use-fake-device-for-media-stream`,
];
const factory = {
create: async () => {
const { headless, path, ignoreHTTPSErrors, endpoint, token } = browser;
const args = ARGS.slice();
if (endpoint) {
if (token) args.push(`token=${token}`);
return await puppeteer.connect({
browserWSEndpoint: `${endpoint}?${args.join('&')}`,
ignoreHTTPSErrors,
});
} else {
return await puppeteer.launch({
headless,
executablePath: path,
ignoreHTTPSErrors,
args,
});
}
},
destroy: function(puppeteer) {
puppeteer.close();
}
}
const size = { max: browser.pool.size.max, min: browser.pool.size.min };
const browsers = genericPool.createPool(factory, size);
const population = Math.ceil(bot.population / browser.pool.size.max);
module.exports = {
browsers,
population,
size: Math.ceil(bot.population / population),
};