-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpuppeteer-core.js
119 lines (105 loc) · 3.16 KB
/
puppeteer-core.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
const {exec} = require('child_process');
const path = require('path');
const testVersion = require('./lib/testVersion');
const include = require('./test/lib/support/include');
const chromeToPupeteer = [
/*
* This list is updated only when updating module, so very sporadically.
* For complete list, see:
* https://pptr.dev/supported-browsers#supported-browser-version-list
*/
// Chromium version, Last compatible puppeteer version
['131.0.6778.264', '24.0.0'],
['131.0.6778.204', '23.11.1'],
['127.0.6533.88', '22.15.0'],
['121.0.6167.85', '21.9.0'],
['115.0.5790.102', '21.0.0'],
['115.0.5790.98', '20.9.0'],
['114.0.5735.133', '20.7.2'],
['112.0.5614.0', '19.8.0'],
['111.0.5556.0', '19.7.0'],
['110.0.5479.0', '19.6.0'],
['109.0.5412.0', '19.4.0'],
['108.0.5351.0', '19.2.0'],
['107.0.5296.0', '18.1.0'],
['106.0.5249.0', '17.1.0'],
['105.0.5173.0', '15.5.0'],
['104.0.5109.0', '15.1.0'],
['103.0.5059.0', '14.2.0'],
['102.0.5002.0', '14.0.0'],
['101.0.4950.0', '13.6.0'],
['100.0.4889.0', '13.5.0'],
['99.0.4844.16', '13.2.0'],
['98.0.4758.0', '13.1.0'],
['97.0.4692.0', '12.0.0'],
['93.0.4577.0', '11.0.0'],
['92.0.4512.0', '10.1.0'],
['91.0.4469.0', '9.1.1'],
['90.0.4427.0', '8.0.0'],
['90.0.4403.0', '7.1.0'],
['89.0.4389.0', '6.0.0'],
['88.0.4298.0', '5.5.0'],
['87.0.4272.0', '5.4.1'],
['86.0.4240.0', '5.3.1'],
['85.0.4182.0', '5.2.1'],
['84.0.4147.0', '5.2.0'],
['62.0.3188.0', '5.0.0']
];
process.once('quit', err => {
if (err) {
console.error(err);
}
process.exit(err ? -1 : 0); // eslint-disable-line no-process-exit
});
const chrome = process.env.CHROME_BIN || null;
if (!chrome) {
console.error('No CHROME_BIN specified in environment, exiting.');
process.exit(-1); // eslint-disable-line no-process-exit
}
exec(`${chrome} --product-version`, (error, stdout) => {
if (error) {
process.emit('quit', error);
return;
}
const chromeVersion = stdout.replaceAll(/[\r\n]/g, '');
var puppeteerVersion = null;
for (const [targetChromeVersion, maxPuppeteerVersion] of chromeToPupeteer) {
if (testVersion(chromeVersion, targetChromeVersion)) {
puppeteerVersion = maxPuppeteerVersion;
break;
}
}
if (!puppeteerVersion) {
process.emit('quit', new Error(`Could not find puppeteer-core version compatible with chrome v${chromeVersion}`));
return;
}
const depsToInstall = [`puppeteer-core@${puppeteerVersion}`, 'serve-files'];
var numOfInstalledDeps = 0;
for (const dep of depsToInstall) {
const [name, version] = dep.split('@');
if (!include(name)) {
continue;
}
// eslint-disable-next-line global-require
if (version && version !== require(path.join(path.dirname(require.resolve(name)), 'package.json')).version) {
continue;
}
numOfInstalledDeps += 1;
}
if (depsToInstall.length <= numOfInstalledDeps) {
console.log('All dependencies already installed.');
process.emit('quit');
return;
}
const depsString = depsToInstall.join(' ');
console.log(`Installing ${depsString}...`);
exec(`npm install --no-save ${depsString}`, (failure, out, err) => {
if (failure) {
console.error(err);
process.emit('quit', failure);
return;
}
console.log(`Installed ${depsString}`);
process.emit('quit');
});
});