webdriver-installer 1.1.5 → 1.1.6

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.1.6](https://github.com/shaka-project/webdriver-installer/compare/v1.1.5...v1.1.6) (2023-07-19)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * Ignore errors executing non-executable drivers ([#23](https://github.com/shaka-project/webdriver-installer/issues/23)) ([07c8644](https://github.com/shaka-project/webdriver-installer/commit/07c864446e68e6f8714c3d1a899b42b2d0931aae)), closes [#22](https://github.com/shaka-project/webdriver-installer/issues/22)
9
+ * Retry when WebDriver updates are not available yet ([#24](https://github.com/shaka-project/webdriver-installer/issues/24)) ([e0312c8](https://github.com/shaka-project/webdriver-installer/commit/e0312c89eab70bbb7241298846dff93e4a690753))
10
+
3
11
  ## [1.1.5](https://github.com/shaka-project/webdriver-installer/compare/v1.1.4...v1.1.5) (2022-12-14)
4
12
 
5
13
 
package/chrome.js CHANGED
@@ -63,9 +63,11 @@ class ChromeWebDriverInstaller extends WebDriverInstallerBase {
63
63
  * @return {!Promise<string>}
64
64
  */
65
65
  async getBestDriverVersion(browserVersion) {
66
- const majorVersion = browserVersion.split('.')[0];
67
- const versionUrl = `${CDN_URL}/LATEST_RELEASE_${majorVersion}`;
68
- return await InstallerUtils.fetchVersionUrl(versionUrl);
66
+ const idealMajorVersion = parseInt(browserVersion.split('.')[0], 10);
67
+ return await InstallerUtils.fetchVersionUrlWithAutomaticDowngrade(
68
+ idealMajorVersion,
69
+ /* minMajorVersion */ idealMajorVersion - 2,
70
+ (majorVersion) => `${CDN_URL}/LATEST_RELEASE_${majorVersion}`);
69
71
  }
70
72
 
71
73
  /**
package/edge.js CHANGED
@@ -63,7 +63,7 @@ class EdgeWebDriverInstaller extends WebDriverInstallerBase {
63
63
  * @return {!Promise<string>}
64
64
  */
65
65
  async getBestDriverVersion(browserVersion) {
66
- const majorVersion = browserVersion.split('.')[0];
66
+ const idealMajorVersion = parseInt(browserVersion.split('.')[0], 10);
67
67
 
68
68
  let platform;
69
69
  if (os.platform() == 'linux') {
@@ -76,8 +76,15 @@ class EdgeWebDriverInstaller extends WebDriverInstallerBase {
76
76
  throw new Error(`Unrecognized platform: ${os.platform()}`);
77
77
  }
78
78
 
79
- const versionUrl = `${CDN_URL}/LATEST_RELEASE_${majorVersion}_${platform}`;
80
- return await InstallerUtils.fetchVersionUrl(versionUrl, 'UTF-16LE');
79
+ const urlFormatter = (majorVersion) => {
80
+ return `${CDN_URL}/LATEST_RELEASE_${majorVersion}_${platform}`;
81
+ };
82
+
83
+ return await InstallerUtils.fetchVersionUrlWithAutomaticDowngrade(
84
+ idealMajorVersion,
85
+ /* minMajorVersion */ idealMajorVersion - 2,
86
+ urlFormatter,
87
+ 'UTF-16LE');
81
88
  }
82
89
 
83
90
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webdriver-installer",
3
- "version": "1.1.5",
3
+ "version": "1.1.6",
4
4
  "description": "Install the right WebDriver version for your local browsers, automatically.",
5
5
  "main": "main.js",
6
6
  "bin": {
package/utils.js CHANGED
@@ -59,6 +59,11 @@ class InstallerUtils {
59
59
  if (error.code == 'ENOENT') {
60
60
  // Command does not exist.
61
61
  return null;
62
+ } else if (error.code == 'EACCES') { // Missing "s" is not a typo!
63
+ // Command is not executable. This can happen after a failed run that
64
+ // downloads something, but is interrupted before setting its
65
+ // executable bit.
66
+ return null;
62
67
  } else {
63
68
  // Command exists, but failed.
64
69
  throw error;
@@ -76,7 +81,8 @@ class InstallerUtils {
76
81
  const response = await fetch(url);
77
82
  if (!response.ok) {
78
83
  throw new Error(
79
- `Failed to fetch ${url}: ${response.status} ${response.statusText}`);
84
+ `Failed to fetch ${url}: ${response.status} ${response.statusText}`,
85
+ { cause: response });
80
86
  }
81
87
  return response;
82
88
  }
@@ -223,7 +229,7 @@ class InstallerUtils {
223
229
  }
224
230
 
225
231
  /**
226
- * Fetch a version number from a URL. Both Chrome and Edge use this.
232
+ * Fetch a version number from a URL.
227
233
  *
228
234
  * @param {string} url
229
235
  * @param {string=} encoding
@@ -236,6 +242,50 @@ class InstallerUtils {
236
242
  return data.toString(encoding).trim();
237
243
  }
238
244
 
245
+ /**
246
+ * Fetch a version number from a URL. If not found, downgrade the major
247
+ * version and try again. If a WebDriver release lags the browser release
248
+ * (which seems common), this will compensate. Both Chrome and Edge use
249
+ * this.
250
+ *
251
+ * @param {number} idealMajorVersion
252
+ * @param {number} minMajorVersion
253
+ * @param {function(number): string} urlFormatter
254
+ * @param {string=} encoding
255
+ * @return {!Promise<string>}
256
+ */
257
+ static async fetchVersionUrlWithAutomaticDowngrade(
258
+ idealMajorVersion, minMajorVersion, urlFormatter, encoding) {
259
+ let majorVersion = idealMajorVersion;
260
+ let firstError = null;
261
+
262
+ while (majorVersion >= minMajorVersion) {
263
+ const versionUrl = urlFormatter(majorVersion);
264
+ try {
265
+ return await InstallerUtils.fetchVersionUrl(versionUrl, encoding);
266
+ } catch (error) {
267
+ if (error.cause.status != 404) {
268
+ // Any unexpected error (other than HTTP 404) is thrown immediately.
269
+ throw error;
270
+ }
271
+
272
+ // Save the first error in case we run out this loop. We'll throw this
273
+ // one if none of the allowed versions can be found.
274
+ if (firstError == null) {
275
+ firstError = error;
276
+ }
277
+
278
+ // For 404 errors, decrease the major version, fall through, loop, and
279
+ // try again.
280
+ majorVersion--;
281
+ }
282
+ }
283
+
284
+ // We tried all allowed versions. Throw the initial error, which will have
285
+ // details of the first URL we tried.
286
+ throw firstError;
287
+ }
288
+
239
289
  /**
240
290
  * Fetch the latest tag from a GitHub repo.
241
291
  *