chromedriver 122.0.0 → 122.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -2
- package/install.js +55 -30
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -68,8 +68,17 @@ See [Chrome for Testing](https://googlechromelabs.github.io/chrome-for-testing/)
|
|
|
68
68
|
how these urls work.
|
|
69
69
|
|
|
70
70
|
Npm config:
|
|
71
|
-
|
|
72
|
-
For
|
|
71
|
+
|
|
72
|
+
For metadata use `chromedriver_cdnurl`. The default is `https://googlechromelabs.github.io`. You need to either supply the binary download endpoint, or the binaries url config, see bellow.
|
|
73
|
+
|
|
74
|
+
For binaries use `chromedriver_cdnbinariesurl`. The default is to search for the download url using
|
|
75
|
+
`$chromedriver_cdnurl/chrome-for-testing/[version].json`, which forms a URL like:
|
|
76
|
+
https://googlechromelabs.github.io/chrome-for-testing/122.0.6261.57.json.
|
|
77
|
+
|
|
78
|
+
The resulting url will be something like:
|
|
79
|
+
https://storage.googleapis.com/chrome-for-testing-public/122.0.6261.57/linux64/chromedriver-linux64.zip.
|
|
80
|
+
|
|
81
|
+
Keep in mind that this last url is just an example and it might change (as it has happened in the past).
|
|
73
82
|
|
|
74
83
|
```shell
|
|
75
84
|
npm install chromedriver --chromedriver_cdnurl=https://npmmirror.com/metadata --chromedriver_cdnbinariesurl=https://npmmirror.com/binaries
|
package/install.js
CHANGED
|
@@ -54,17 +54,23 @@ if (skipDownload) {
|
|
|
54
54
|
const majorVersion = parseInt(chromedriverVersion.split('.')[0]);
|
|
55
55
|
const useLegacyMethod = majorVersion <= 114;
|
|
56
56
|
const platform = getPlatform(chromedriverVersion);
|
|
57
|
-
|
|
58
|
-
if (!useLegacyMethod)
|
|
57
|
+
const downloadedFile = getDownloadFilePath(useLegacyMethod, tmpPath, platform);
|
|
58
|
+
if (!useLegacyMethod)
|
|
59
59
|
tmpPath = path.join(tmpPath, path.basename(downloadedFile, path.extname(downloadedFile)));
|
|
60
|
-
}
|
|
61
60
|
const chromedriverBinaryFileName = process.platform === 'win32' ? 'chromedriver.exe' : 'chromedriver';
|
|
62
61
|
const chromedriverBinaryFilePath = path.resolve(tmpPath, chromedriverBinaryFileName);
|
|
63
62
|
const chromedriverIsAvailable = await verifyIfChromedriverIsAvailableAndHasCorrectVersion(chromedriverVersion, chromedriverBinaryFilePath);
|
|
64
63
|
if (!chromedriverIsAvailable) {
|
|
65
64
|
console.log('Current existing ChromeDriver binary is unavailable, proceeding with download and extraction.');
|
|
66
|
-
const
|
|
67
|
-
|
|
65
|
+
const configuredfilePath = process.env.npm_config_chromedriver_filepath || process.env.CHROMEDRIVER_FILEPATH;
|
|
66
|
+
if (configuredfilePath) {
|
|
67
|
+
console.log('Using file: ', configuredfilePath);
|
|
68
|
+
return configuredfilePath;
|
|
69
|
+
}
|
|
70
|
+
if (useLegacyMethod)
|
|
71
|
+
await downloadFileLegacy(legacyCdnUrl, downloadedFile, chromedriverVersion);
|
|
72
|
+
else
|
|
73
|
+
await downloadFile(cdnUrl, downloadedFile, chromedriverVersion, platform);
|
|
68
74
|
await extractDownload(extractDirectory, chromedriverBinaryFilePath, downloadedFile);
|
|
69
75
|
}
|
|
70
76
|
const libPath = path.join(__dirname, 'lib', 'chromedriver');
|
|
@@ -86,14 +92,14 @@ function getPlatform(chromedriverVersion) {
|
|
|
86
92
|
if (process.arch === 'arm64' || process.arch === 's390x' || process.arch === 'x64') {
|
|
87
93
|
return 'linux64';
|
|
88
94
|
} else {
|
|
89
|
-
console.
|
|
95
|
+
console.error('Only Linux 64 bits supported.');
|
|
90
96
|
process.exit(1);
|
|
91
97
|
}
|
|
92
98
|
} else if (thePlatform === 'darwin' || thePlatform === 'freebsd') {
|
|
93
99
|
const osxPlatform = getMacOsRealArch(chromedriverVersion);
|
|
94
100
|
|
|
95
101
|
if (!osxPlatform) {
|
|
96
|
-
console.
|
|
102
|
+
console.error('Only Mac 64 bits supported.');
|
|
97
103
|
process.exit(1);
|
|
98
104
|
}
|
|
99
105
|
|
|
@@ -104,36 +110,38 @@ function getPlatform(chromedriverVersion) {
|
|
|
104
110
|
}
|
|
105
111
|
return (process.arch === 'x64') ? 'win64' : 'win32';
|
|
106
112
|
}
|
|
107
|
-
|
|
108
|
-
console.log('Unexpected platform or architecture:', process.platform, process.arch);
|
|
113
|
+
console.error('Unexpected platform or architecture:', process.platform, process.arch);
|
|
109
114
|
process.exit(1);
|
|
110
115
|
}
|
|
111
116
|
|
|
112
117
|
/**
|
|
113
118
|
* @param {string} cdnUrl
|
|
114
|
-
* @param {boolean} useLegacyDownloadMethod
|
|
115
119
|
* @param {string} downloadedFile
|
|
116
120
|
* @param {string} chromedriverVersion
|
|
117
121
|
* @param {string} platform
|
|
118
122
|
*/
|
|
119
|
-
async function downloadFile(cdnUrl,
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const formattedDownloadUrl = `${cdnUrl}/${chromedriverVersion}/${fileName}`;
|
|
128
|
-
console.log('Downloading from file: ', formattedDownloadUrl);
|
|
129
|
-
await requestBinary(getRequestOptions(formattedDownloadUrl), downloadedFile);
|
|
130
|
-
} else {
|
|
131
|
-
const formattedDownloadUrl = `${cdnUrl}/${chromedriverVersion}/${platform}/${fileName}`;
|
|
132
|
-
console.log('Downloading from file: ', formattedDownloadUrl);
|
|
133
|
-
await requestBinary(getRequestOptions(formattedDownloadUrl), downloadedFile);
|
|
134
|
-
}
|
|
135
|
-
return downloadedFile;
|
|
123
|
+
async function downloadFile(cdnUrl, downloadedFile, chromedriverVersion, platform) {
|
|
124
|
+
const cdnBinariesUrl = (process.env.npm_config_chromedriver_cdnbinariesurl || process.env.CHROMEDRIVER_CDNBINARIESURL)?.replace(/\/+$/, '');
|
|
125
|
+
const url = cdnBinariesUrl
|
|
126
|
+
? `${cdnBinariesUrl}/${chromedriverVersion}/${platform}/${path.basename(downloadedFile)}`
|
|
127
|
+
: await getDownloadUrl(cdnUrl, chromedriverVersion, platform);
|
|
128
|
+
if (!url) {
|
|
129
|
+
console.error(`Download url could not be found for version ${chromedriverVersion} and platform '${platform}'`);
|
|
130
|
+
process.exit(1);
|
|
136
131
|
}
|
|
132
|
+
console.log('Downloading from file: ', url);
|
|
133
|
+
await requestBinary(getRequestOptions(url), downloadedFile);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* @param {string} cdnUrl
|
|
138
|
+
* @param {string} downloadedFile
|
|
139
|
+
* @param {string} chromedriverVersion
|
|
140
|
+
*/
|
|
141
|
+
async function downloadFileLegacy(cdnUrl, downloadedFile, chromedriverVersion) {
|
|
142
|
+
const url = `${cdnUrl}/${chromedriverVersion}/${path.basename(downloadedFile)}`;
|
|
143
|
+
console.log('Downloading from file: ', url);
|
|
144
|
+
await requestBinary(getRequestOptions(url), downloadedFile);
|
|
137
145
|
}
|
|
138
146
|
|
|
139
147
|
/**
|
|
@@ -309,6 +317,21 @@ async function getChromeDriverVersion(cdnUrl, legacyCdnUrl, majorVersion) {
|
|
|
309
317
|
}
|
|
310
318
|
}
|
|
311
319
|
|
|
320
|
+
/**
|
|
321
|
+
* @param {string} cdnUrl
|
|
322
|
+
* @param {string} version
|
|
323
|
+
* @param {string} platform
|
|
324
|
+
* @returns {Promise<[string]>}
|
|
325
|
+
*/
|
|
326
|
+
async function getDownloadUrl(cdnUrl, version, platform) {
|
|
327
|
+
const getUrlUrl = `${cdnUrl}/chrome-for-testing/${version}.json`;
|
|
328
|
+
const requestOptions = getRequestOptions(getUrlUrl);
|
|
329
|
+
// @ts-expect-error
|
|
330
|
+
const response = await axios.request(requestOptions);
|
|
331
|
+
const url = response.data?.downloads?.chromedriver?.find((/** @type {{ platform: string; }} */ c) => c.platform == platform)?.url;
|
|
332
|
+
return url;
|
|
333
|
+
}
|
|
334
|
+
|
|
312
335
|
/**
|
|
313
336
|
*
|
|
314
337
|
* @param {import('axios').AxiosRequestConfig} requestOptions
|
|
@@ -321,11 +344,12 @@ async function requestBinary(requestOptions, filePath) {
|
|
|
321
344
|
// @ts-expect-error
|
|
322
345
|
response = await axios.request({ responseType: 'stream', ...requestOptions });
|
|
323
346
|
} catch (error) {
|
|
347
|
+
let errorData = '';
|
|
324
348
|
if (error && error.response) {
|
|
325
349
|
if (error.response.status)
|
|
326
350
|
console.error('Error status code:', error.response.status);
|
|
327
351
|
if (error.response.data) {
|
|
328
|
-
error.response.data.on('data', data =>
|
|
352
|
+
error.response.data.on('data', data => errorData += data.toString('utf8'));
|
|
329
353
|
try {
|
|
330
354
|
await finishedAsync(error.response.data);
|
|
331
355
|
} catch (error) {
|
|
@@ -333,7 +357,8 @@ async function requestBinary(requestOptions, filePath) {
|
|
|
333
357
|
}
|
|
334
358
|
}
|
|
335
359
|
}
|
|
336
|
-
|
|
360
|
+
console.error(`Error with http(s) request:\n${error}\nError data:\n${errorData}`);
|
|
361
|
+
process.exit(1);
|
|
337
362
|
}
|
|
338
363
|
let count = 0;
|
|
339
364
|
let notifiedCount = 0;
|
|
@@ -359,7 +384,7 @@ async function requestBinary(requestOptions, filePath) {
|
|
|
359
384
|
*/
|
|
360
385
|
async function extractDownload(dirToExtractTo, chromedriverBinaryFilePath, downloadedFile) {
|
|
361
386
|
if (path.extname(downloadedFile) !== '.zip') {
|
|
362
|
-
fs.mkdirSync(path.dirname(chromedriverBinaryFilePath), {recursive: true});
|
|
387
|
+
fs.mkdirSync(path.dirname(chromedriverBinaryFilePath), { recursive: true });
|
|
363
388
|
fs.copyFileSync(downloadedFile, chromedriverBinaryFilePath);
|
|
364
389
|
console.log('Skipping zip extraction - binary file found.');
|
|
365
390
|
return;
|