From 8cc247e8f06a8fb12d492d5d4159c55cadc95bba Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Sun, 20 Oct 2024 22:12:20 -0700 Subject: [PATCH 01/19] feat: add install chromedriver command --- package.json | 9 +++- scripts/install-chromedriver.mjs | 70 ++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 scripts/install-chromedriver.mjs diff --git a/package.json b/package.json index 6a21ac1e..666e1d29 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,8 @@ "README.md", "CHANGELOG.md", "LICENSE", - "npm-shrinkwrap.json" + "npm-shrinkwrap.json", + "scripts/*.mjs" ], "scripts": { "build": "tsc -b", @@ -57,6 +58,7 @@ }, "dependencies": { "appium-chromedriver": "6.0.8", + "axios": "^1.6.5", "bluebird": "3.7.2", "lodash": "4.17.21" }, @@ -80,7 +82,10 @@ "macOS", "Linux" ], - "mainClass": "ChromiumDriver" + "mainClass": "ChromiumDriver", + "scripts": { + "install-chromedriver": "./scripts/install-chromedriver.mjs" + } }, "typedoc": { "entryPoint": "./build/lib/index.js" diff --git a/scripts/install-chromedriver.mjs b/scripts/install-chromedriver.mjs new file mode 100644 index 00000000..b3f4afd9 --- /dev/null +++ b/scripts/install-chromedriver.mjs @@ -0,0 +1,70 @@ +import _ from 'lodash'; +import { ChromedriverStorageClient } from 'appium-chromedriver'; +import axios from 'axios'; + +const VERSION_LATEST = 'LATEST'; + +function getChromedriverUrl() { + return process.env.CHROMELABS_URL || 'https://googlechromelabs.github.io' +} + +function getChromedriverVersion() { + return process.env.npm_config_chromedriver_version || + process.env.CHROMEDRIVER_VERSION || + VERSION_LATEST; +} + +async function formatCdVersion (ver) { + if (_.toUpper(ver) !== VERSION_LATEST) { + return ver; + } + let jsonStr; + const url = `${getChromedriverUrl()}/chrome-for-testing/last-known-good-versions.json`; + try { + jsonStr = (await axios({ + url, + headers: { + 'user-agent': 'appium', + accept: `application/json, */*`, + }, + timeout: 15000, + responseType: 'text', + })).data; + } catch (e) { + throw new Error(`Cannot fetch the latest Chromedriver version. ` + + `Make sure you can access ${url} from your machine or provide a mirror by setting ` + + `a custom value to CHROMELABS_URL enironment variable. Original error: ${err.message}`); + } + + let json; + try { + json = JSON.parse(jsonStr); + } catch (e) { + const err = /** @type {Error} */ (e); + throw new Error(`Storage JSON cannot be parsed. Original error: ${err.message}`); + } + /** + * "timestamp":"2024-10-20T20:09:22.942Z", + * "channels":{ + * "Stable":{ + * "channel":"Stable", + * "version":"130.0.6723.58", + * "revision":"1356013" + * ... + */ + if (!json?.channels?.Stable?.version) { + throw new Error('The format of the storage JSON is not supported'); + } + return json.channels.Stable.version; + } + +async function install () { + const client = new ChromedriverStorageClient({ + chromedriverDir: import.meta.dirname, + }); + await client.syncDrivers({ + versions: [await formatCdVersion(getChromedriverVersion())], + }); +} + +(async () => await install())(); From 5cb0ec55eb0a2e08590553d88b517a811fb50a46 Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Sun, 20 Oct 2024 22:12:42 -0700 Subject: [PATCH 02/19] run npm install --- package-lock.json | 81 ++++++++++------------------------------------- 1 file changed, 17 insertions(+), 64 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2a9c7a45..a3cf617e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,16 @@ { "name": "appium-chromium-driver", - "version": "1.3.54", + "version": "1.3.55", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "appium-chromium-driver", - "version": "1.3.54", + "version": "1.3.55", "license": "Apache-2.0", "dependencies": { "appium-chromedriver": "6.0.8", + "axios": "^1.6.5", "bluebird": "3.7.2", "lodash": "4.17.21" }, @@ -634,17 +635,6 @@ "node": ">=8.0.0" } }, - "node_modules/@appium/base-driver/node_modules/axios": { - "version": "1.7.7", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz", - "integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==", - "license": "MIT", - "dependencies": { - "follow-redirects": "^1.15.6", - "form-data": "^4.0.0", - "proxy-from-env": "^1.1.0" - } - }, "node_modules/@appium/base-driver/node_modules/brace-expansion": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", @@ -1481,18 +1471,6 @@ "node": ">=8.0.0" } }, - "node_modules/@appium/base-plugin/node_modules/axios": { - "version": "1.7.7", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz", - "integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==", - "license": "MIT", - "peer": true, - "dependencies": { - "follow-redirects": "^1.15.6", - "form-data": "^4.0.0", - "proxy-from-env": "^1.1.0" - } - }, "node_modules/@appium/base-plugin/node_modules/brace-expansion": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", @@ -2365,18 +2343,6 @@ "node": ">=8.0.0" } }, - "node_modules/@appium/docutils/node_modules/axios": { - "version": "1.7.7", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz", - "integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==", - "license": "MIT", - "peer": true, - "dependencies": { - "follow-redirects": "^1.15.6", - "form-data": "^4.0.0", - "proxy-from-env": "^1.1.0" - } - }, "node_modules/@appium/docutils/node_modules/brace-expansion": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", @@ -2786,6 +2752,16 @@ "npm": ">=8" } }, + "node_modules/@appium/support/node_modules/axios": { + "version": "1.6.3", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.3.tgz", + "integrity": "sha512-fWyNdeawGam70jXSVlKl+SUNVcL6j6W79CuSIPfi6HnDUmSCH6gyUys/HrqHeA/wU0Az41rRgean494d0Jb+ww==", + "dependencies": { + "follow-redirects": "^1.15.0", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, "node_modules/@appium/support/node_modules/type-fest": { "version": "4.9.0", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.9.0.tgz", @@ -5944,17 +5920,6 @@ "node": ">=8.0.0" } }, - "node_modules/appium-chromedriver/node_modules/axios": { - "version": "1.7.7", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz", - "integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==", - "license": "MIT", - "dependencies": { - "follow-redirects": "^1.15.6", - "form-data": "^4.0.0", - "proxy-from-env": "^1.1.0" - } - }, "node_modules/appium-chromedriver/node_modules/brace-expansion": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", @@ -6790,18 +6755,6 @@ "node": ">=8.0.0" } }, - "node_modules/appium/node_modules/axios": { - "version": "1.7.7", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz", - "integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==", - "license": "MIT", - "peer": true, - "dependencies": { - "follow-redirects": "^1.15.6", - "form-data": "^4.0.0", - "proxy-from-env": "^1.1.0" - } - }, "node_modules/appium/node_modules/brace-expansion": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", @@ -7406,11 +7359,11 @@ } }, "node_modules/axios": { - "version": "1.6.3", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.3.tgz", - "integrity": "sha512-fWyNdeawGam70jXSVlKl+SUNVcL6j6W79CuSIPfi6HnDUmSCH6gyUys/HrqHeA/wU0Az41rRgean494d0Jb+ww==", + "version": "1.7.7", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz", + "integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==", "dependencies": { - "follow-redirects": "^1.15.0", + "follow-redirects": "^1.15.6", "form-data": "^4.0.0", "proxy-from-env": "^1.1.0" } From 81a9efed11c754c8330d6a45a7d56cea53d91b6d Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Sun, 20 Oct 2024 22:40:49 -0700 Subject: [PATCH 03/19] docs: add scripts --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 73be9058..32dedeea 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,22 @@ this driver supports the following: > **Note** > `msedgedriver` support is limited. `appium:autodownloadEnabled` does not work for the driver, thus `appium:executable` is necessary to automate MSEdge browser properly. +## Scripts + +### install-chromedriver + +This script is used to install the given or latest stable version of chromedriver from +[Chorme for testing](https://github.com/GoogleChromeLabs/chrome-for-testing) +with `appium driver run chromium install-chromedriver`. + +As same as [appium-chromedriver](https://github.com/appium/appium-chromedriver), +`CHROMEDRIVER_VERSION` and `CHROMELABS_URL` environment variables are available. + +`CHROMEDRIVER_VERSION` lets the command download a specific chromedriver. i.e. `CHROMEDRIVER_VERSION=131.0.6778.3 appium driver run chromium install-chromedriver` + +`CHROMELABS_URL` lets the command get the list of available chromedrivers from instead of the default `https://googlechromelabs.github.io`. + + ## Contributing Contributions to this project are welcome! Feel free to submit a PR on GitHub. From 8fcaf7076061af4dfff83ac4f5cd3a19b428e252 Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Sun, 20 Oct 2024 22:46:20 -0700 Subject: [PATCH 04/19] tweak --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 32dedeea..a0cfa971 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ this driver supports the following: This script is used to install the given or latest stable version of chromedriver from [Chorme for testing](https://github.com/GoogleChromeLabs/chrome-for-testing) -with `appium driver run chromium install-chromedriver`. +in `node_modules/appium-chromedriver/chromedriver` directory with `appium driver run chromium install-chromedriver`. As same as [appium-chromedriver](https://github.com/appium/appium-chromedriver), `CHROMEDRIVER_VERSION` and `CHROMELABS_URL` environment variables are available. From 1ba5e79d6952904c242e2c4ac9a75667efc19d3a Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Mon, 21 Oct 2024 00:05:10 -0700 Subject: [PATCH 05/19] docs: update readme --- README.md | 24 +++++++++++++----------- package-lock.json | 3 +-- package.json | 2 +- scripts/install-chromedriver.mjs | 6 +++++- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index a0cfa971..8028f65e 100644 --- a/README.md +++ b/README.md @@ -81,17 +81,19 @@ this driver supports the following: ### install-chromedriver -This script is used to install the given or latest stable version of chromedriver from -[Chorme for testing](https://github.com/GoogleChromeLabs/chrome-for-testing) -in `node_modules/appium-chromedriver/chromedriver` directory with `appium driver run chromium install-chromedriver`. - -As same as [appium-chromedriver](https://github.com/appium/appium-chromedriver), -`CHROMEDRIVER_VERSION` and `CHROMELABS_URL` environment variables are available. - -`CHROMEDRIVER_VERSION` lets the command download a specific chromedriver. i.e. `CHROMEDRIVER_VERSION=131.0.6778.3 appium driver run chromium install-chromedriver` - -`CHROMELABS_URL` lets the command get the list of available chromedrivers from instead of the default `https://googlechromelabs.github.io`. - +This script is used to install the given or latest stable version of chromedriver (113+) from +[Chrome for testing](https://github.com/GoogleChromeLabs/chrome-for-testing) +with `appium driver run chromium install-chromedriver`. + +Below environment arguments are available: +- `CHROMEDRIVERS_EXECUTABLE_DIR` + - Let the command to download chromedrivers in the given directory. Defaults to `node_modules/appium-chromedriver/chromedriver`. + - `CHROMEDRIVERS_EXECUTABLE_DIR=/Users/tmp/chromedrivers appium driver run chromium install-chromedriver` +- `CHROMEDRIVER_VERSION` + - Let the command download a specific version. + - i.e. `CHROMEDRIVER_VERSION=131.0.6778.3 appium driver run chromium install-chromedriver` +- `CHROMELABS_URL` + - Let the command get the list of available chromedrivers from instead of the default `https://googlechromelabs.github.io`. ## Contributing diff --git a/package-lock.json b/package-lock.json index a3cf617e..879f6fb1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "1.3.55", "license": "Apache-2.0", "dependencies": { - "appium-chromedriver": "6.0.8", + "appium-chromedriver": "^6.0.8", "axios": "^1.6.5", "bluebird": "3.7.2", "lodash": "4.17.21" @@ -5332,7 +5332,6 @@ "version": "6.0.8", "resolved": "https://registry.npmjs.org/appium-chromedriver/-/appium-chromedriver-6.0.8.tgz", "integrity": "sha512-TncJo4dsHAwu1UDCAJxcm/JjQ4Gf24fJKBgpPYOAsALFkV6F6mOruMRtb9Bxhs17akJnn2Gb4+3lnbj8U/55eg==", - "license": "Apache-2.0", "dependencies": { "@appium/base-driver": "^9.1.0", "@appium/support": "^5.1.1", diff --git a/package.json b/package.json index 666e1d29..90271043 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "singleQuote": true }, "dependencies": { - "appium-chromedriver": "6.0.8", + "appium-chromedriver": "^6.0.8", "axios": "^1.6.5", "bluebird": "3.7.2", "lodash": "4.17.21" diff --git a/scripts/install-chromedriver.mjs b/scripts/install-chromedriver.mjs index b3f4afd9..b270c56a 100644 --- a/scripts/install-chromedriver.mjs +++ b/scripts/install-chromedriver.mjs @@ -14,6 +14,10 @@ function getChromedriverVersion() { VERSION_LATEST; } +function getExecutableDir() { + return process.env.CHROMEDRIVERS_EXECUTABLE_DIR || import.meta.dirname +} + async function formatCdVersion (ver) { if (_.toUpper(ver) !== VERSION_LATEST) { return ver; @@ -60,7 +64,7 @@ async function formatCdVersion (ver) { async function install () { const client = new ChromedriverStorageClient({ - chromedriverDir: import.meta.dirname, + chromedriverDir: getExecutableDir(), }); await client.syncDrivers({ versions: [await formatCdVersion(getChromedriverVersion())], From 13089acc7ec484f11b9d75720aec1e8a1e962171 Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Mon, 21 Oct 2024 00:07:05 -0700 Subject: [PATCH 06/19] remove .mjs --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 90271043..8a6b38e2 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "CHANGELOG.md", "LICENSE", "npm-shrinkwrap.json", - "scripts/*.mjs" + "scripts" ], "scripts": { "build": "tsc -b", From 720073ac14930d83ce3e0d4bcd7e5059350d7417 Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Mon, 21 Oct 2024 00:08:20 -0700 Subject: [PATCH 07/19] tweak naming --- README.md | 4 ++-- scripts/install-chromedriver.mjs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8028f65e..0dab26d5 100644 --- a/README.md +++ b/README.md @@ -86,9 +86,9 @@ This script is used to install the given or latest stable version of chromedrive with `appium driver run chromium install-chromedriver`. Below environment arguments are available: -- `CHROMEDRIVERS_EXECUTABLE_DIR` +- `CHROMEDRIVER_EXECUTABLE_DIR` - Let the command to download chromedrivers in the given directory. Defaults to `node_modules/appium-chromedriver/chromedriver`. - - `CHROMEDRIVERS_EXECUTABLE_DIR=/Users/tmp/chromedrivers appium driver run chromium install-chromedriver` + - `CHROMEDRIVER_EXECUTABLE_DIR=/Users/tmp/chromedrivers appium driver run chromium install-chromedriver` - `CHROMEDRIVER_VERSION` - Let the command download a specific version. - i.e. `CHROMEDRIVER_VERSION=131.0.6778.3 appium driver run chromium install-chromedriver` diff --git a/scripts/install-chromedriver.mjs b/scripts/install-chromedriver.mjs index b270c56a..7b5a1024 100644 --- a/scripts/install-chromedriver.mjs +++ b/scripts/install-chromedriver.mjs @@ -15,7 +15,7 @@ function getChromedriverVersion() { } function getExecutableDir() { - return process.env.CHROMEDRIVERS_EXECUTABLE_DIR || import.meta.dirname + return process.env.CHROMEDRIVER_EXECUTABLE_DIR || import.meta.dirname } async function formatCdVersion (ver) { From 4871ef71a368ef802633267449d75e27a68d100b Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Mon, 21 Oct 2024 00:11:44 -0700 Subject: [PATCH 08/19] simplify a bit --- scripts/install-chromedriver.mjs | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/scripts/install-chromedriver.mjs b/scripts/install-chromedriver.mjs index 7b5a1024..e32ea427 100644 --- a/scripts/install-chromedriver.mjs +++ b/scripts/install-chromedriver.mjs @@ -22,10 +22,10 @@ async function formatCdVersion (ver) { if (_.toUpper(ver) !== VERSION_LATEST) { return ver; } - let jsonStr; + let versions; const url = `${getChromedriverUrl()}/chrome-for-testing/last-known-good-versions.json`; try { - jsonStr = (await axios({ + versions = (await axios({ url, headers: { 'user-agent': 'appium', @@ -33,20 +33,13 @@ async function formatCdVersion (ver) { }, timeout: 15000, responseType: 'text', - })).data; + })).json; } catch (e) { throw new Error(`Cannot fetch the latest Chromedriver version. ` + `Make sure you can access ${url} from your machine or provide a mirror by setting ` + `a custom value to CHROMELABS_URL enironment variable. Original error: ${err.message}`); } - let json; - try { - json = JSON.parse(jsonStr); - } catch (e) { - const err = /** @type {Error} */ (e); - throw new Error(`Storage JSON cannot be parsed. Original error: ${err.message}`); - } /** * "timestamp":"2024-10-20T20:09:22.942Z", * "channels":{ @@ -56,10 +49,10 @@ async function formatCdVersion (ver) { * "revision":"1356013" * ... */ - if (!json?.channels?.Stable?.version) { + if (!versions?.channels?.Stable?.version) { throw new Error('The format of the storage JSON is not supported'); } - return json.channels.Stable.version; + return versions.channels.Stable.version; } async function install () { From e095149b95c935993f48761f09aa89049376b4c6 Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Mon, 21 Oct 2024 00:12:31 -0700 Subject: [PATCH 09/19] remove npm config --- scripts/install-chromedriver.mjs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/install-chromedriver.mjs b/scripts/install-chromedriver.mjs index e32ea427..fa7cd861 100644 --- a/scripts/install-chromedriver.mjs +++ b/scripts/install-chromedriver.mjs @@ -9,9 +9,7 @@ function getChromedriverUrl() { } function getChromedriverVersion() { - return process.env.npm_config_chromedriver_version || - process.env.CHROMEDRIVER_VERSION || - VERSION_LATEST; + return process.env.CHROMEDRIVER_VERSION || VERSION_LATEST; } function getExecutableDir() { From da40e52c30e70f26bda47ce083b8a969159e26c9 Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Mon, 21 Oct 2024 00:14:13 -0700 Subject: [PATCH 10/19] use appium-chromium-driver --- scripts/install-chromedriver.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install-chromedriver.mjs b/scripts/install-chromedriver.mjs index fa7cd861..2fd48645 100644 --- a/scripts/install-chromedriver.mjs +++ b/scripts/install-chromedriver.mjs @@ -26,7 +26,7 @@ async function formatCdVersion (ver) { versions = (await axios({ url, headers: { - 'user-agent': 'appium', + 'user-agent': 'appium-chromium-driver', accept: `application/json, */*`, }, timeout: 15000, From 5d94b21a6e721405c6165381dadbf8ce09664506 Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Mon, 21 Oct 2024 00:25:56 -0700 Subject: [PATCH 11/19] modify the readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0dab26d5..7f6e8a99 100644 --- a/README.md +++ b/README.md @@ -87,8 +87,8 @@ with `appium driver run chromium install-chromedriver`. Below environment arguments are available: - `CHROMEDRIVER_EXECUTABLE_DIR` - - Let the command to download chromedrivers in the given directory. Defaults to `node_modules/appium-chromedriver/chromedriver`. - - `CHROMEDRIVER_EXECUTABLE_DIR=/Users/tmp/chromedrivers appium driver run chromium install-chromedriver` + - Let the command to download chromedrivers in the given directory. Once you set `appium:executableDir` to the same directory, a new session will refer to the same directory. Defaults to `node_modules/appium-chromedriver/chromedriver` in `appium-chromium-driver` package. + - `CHROMEDRIVER_EXECUTABLE_DIR=/tmp/chromedrivers appium driver run chromium install-chromedriver` - `CHROMEDRIVER_VERSION` - Let the command download a specific version. - i.e. `CHROMEDRIVER_VERSION=131.0.6778.3 appium driver run chromium install-chromedriver` From b398e0e288472afee6dd290356af3473e4f20542 Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Mon, 21 Oct 2024 00:36:32 -0700 Subject: [PATCH 12/19] fix lint --- .eslintrc.json | 7 +++++++ scripts/install-chromedriver.mjs | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 69a602c5..84dc8845 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -6,6 +6,13 @@ "rules": { "func-names": "off" } + }, + { + "files": "scripts/**/*", + "parserOptions": {"sourceType": "module"}, + "rules": { + "@typescript-eslint/no-var-requires": "off" + } } ] } diff --git a/scripts/install-chromedriver.mjs b/scripts/install-chromedriver.mjs index 2fd48645..28bf5546 100644 --- a/scripts/install-chromedriver.mjs +++ b/scripts/install-chromedriver.mjs @@ -5,7 +5,7 @@ import axios from 'axios'; const VERSION_LATEST = 'LATEST'; function getChromedriverUrl() { - return process.env.CHROMELABS_URL || 'https://googlechromelabs.github.io' + return process.env.CHROMELABS_URL || 'https://googlechromelabs.github.io'; } function getChromedriverVersion() { @@ -13,7 +13,7 @@ function getChromedriverVersion() { } function getExecutableDir() { - return process.env.CHROMEDRIVER_EXECUTABLE_DIR || import.meta.dirname + return process.env.CHROMEDRIVER_EXECUTABLE_DIR || import.meta.dirname; } async function formatCdVersion (ver) { @@ -35,7 +35,7 @@ async function formatCdVersion (ver) { } catch (e) { throw new Error(`Cannot fetch the latest Chromedriver version. ` + `Make sure you can access ${url} from your machine or provide a mirror by setting ` + - `a custom value to CHROMELABS_URL enironment variable. Original error: ${err.message}`); + `a custom value to CHROMELABS_URL enironment variable. Original error: ${e.message}`); } /** From 665767c1b5285dc0275a30a0af03e4ca8e523f7b Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Mon, 21 Oct 2024 01:19:53 -0700 Subject: [PATCH 13/19] use getLatestKnownGoodVersion --- scripts/install-chromedriver.mjs | 50 ++------------------------------ 1 file changed, 3 insertions(+), 47 deletions(-) diff --git a/scripts/install-chromedriver.mjs b/scripts/install-chromedriver.mjs index 28bf5546..281a4017 100644 --- a/scripts/install-chromedriver.mjs +++ b/scripts/install-chromedriver.mjs @@ -1,64 +1,20 @@ -import _ from 'lodash'; import { ChromedriverStorageClient } from 'appium-chromedriver'; -import axios from 'axios'; - -const VERSION_LATEST = 'LATEST'; - -function getChromedriverUrl() { - return process.env.CHROMELABS_URL || 'https://googlechromelabs.github.io'; -} function getChromedriverVersion() { - return process.env.CHROMEDRIVER_VERSION || VERSION_LATEST; + return process.env.CHROMEDRIVER_VERSION; } function getExecutableDir() { return process.env.CHROMEDRIVER_EXECUTABLE_DIR || import.meta.dirname; } -async function formatCdVersion (ver) { - if (_.toUpper(ver) !== VERSION_LATEST) { - return ver; - } - let versions; - const url = `${getChromedriverUrl()}/chrome-for-testing/last-known-good-versions.json`; - try { - versions = (await axios({ - url, - headers: { - 'user-agent': 'appium-chromium-driver', - accept: `application/json, */*`, - }, - timeout: 15000, - responseType: 'text', - })).json; - } catch (e) { - throw new Error(`Cannot fetch the latest Chromedriver version. ` + - `Make sure you can access ${url} from your machine or provide a mirror by setting ` + - `a custom value to CHROMELABS_URL enironment variable. Original error: ${e.message}`); - } - - /** - * "timestamp":"2024-10-20T20:09:22.942Z", - * "channels":{ - * "Stable":{ - * "channel":"Stable", - * "version":"130.0.6723.58", - * "revision":"1356013" - * ... - */ - if (!versions?.channels?.Stable?.version) { - throw new Error('The format of the storage JSON is not supported'); - } - return versions.channels.Stable.version; - } - async function install () { const client = new ChromedriverStorageClient({ chromedriverDir: getExecutableDir(), }); + const chromeDriverVersion = getChromedriverVersion() || await client.getLatestKnownGoodVersion(); await client.syncDrivers({ - versions: [await formatCdVersion(getChromedriverVersion())], + versions: [chromeDriverVersion], }); } From 9cb4ad5ba4d2d5700f0587e8eae18c4b9cf344df Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Mon, 21 Oct 2024 19:21:49 -0700 Subject: [PATCH 14/19] use chrome driver 6.1.0 --- package-lock.json | 8 ++++---- package.json | 2 +- scripts/install-chromedriver.mjs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 879f6fb1..c81b5828 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "1.3.55", "license": "Apache-2.0", "dependencies": { - "appium-chromedriver": "^6.0.8", + "appium-chromedriver": "^6.1.0", "axios": "^1.6.5", "bluebird": "3.7.2", "lodash": "4.17.21" @@ -5329,9 +5329,9 @@ } }, "node_modules/appium-chromedriver": { - "version": "6.0.8", - "resolved": "https://registry.npmjs.org/appium-chromedriver/-/appium-chromedriver-6.0.8.tgz", - "integrity": "sha512-TncJo4dsHAwu1UDCAJxcm/JjQ4Gf24fJKBgpPYOAsALFkV6F6mOruMRtb9Bxhs17akJnn2Gb4+3lnbj8U/55eg==", + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/appium-chromedriver/-/appium-chromedriver-6.1.0.tgz", + "integrity": "sha512-mHOB3Dahuk3BDnXAf0AlwXhAzieVoO8b4Thx6GiNBNxklOqjyznViJYuQtT6GmEACIVZmZs1yjZ74rujltMXLw==", "dependencies": { "@appium/base-driver": "^9.1.0", "@appium/support": "^5.1.1", diff --git a/package.json b/package.json index 8a6b38e2..8c0ad3c7 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "singleQuote": true }, "dependencies": { - "appium-chromedriver": "^6.0.8", + "appium-chromedriver": "^6.1.0", "axios": "^1.6.5", "bluebird": "3.7.2", "lodash": "4.17.21" diff --git a/scripts/install-chromedriver.mjs b/scripts/install-chromedriver.mjs index 281a4017..75405862 100644 --- a/scripts/install-chromedriver.mjs +++ b/scripts/install-chromedriver.mjs @@ -5,7 +5,7 @@ function getChromedriverVersion() { } function getExecutableDir() { - return process.env.CHROMEDRIVER_EXECUTABLE_DIR || import.meta.dirname; + return process.env.CHROMEDRIVER_EXECUTABLE_DIR; } async function install () { From 543e486f18bf6c525a40f40fd9aa055287ab928c Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Mon, 21 Oct 2024 19:24:07 -0700 Subject: [PATCH 15/19] remove axios --- package-lock.json | 1 - package.json | 1 - 2 files changed, 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index c81b5828..6606ed22 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,6 @@ "license": "Apache-2.0", "dependencies": { "appium-chromedriver": "^6.1.0", - "axios": "^1.6.5", "bluebird": "3.7.2", "lodash": "4.17.21" }, diff --git a/package.json b/package.json index 8c0ad3c7..ba150b02 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,6 @@ }, "dependencies": { "appium-chromedriver": "^6.1.0", - "axios": "^1.6.5", "bluebird": "3.7.2", "lodash": "4.17.21" }, From a566c94f9d4034d1705876f7de6b38486a37106d Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Mon, 21 Oct 2024 19:26:45 -0700 Subject: [PATCH 16/19] tweak the package-lock --- package-lock.json | 76 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 62 insertions(+), 14 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6606ed22..376d9163 100644 --- a/package-lock.json +++ b/package-lock.json @@ -634,6 +634,17 @@ "node": ">=8.0.0" } }, + "node_modules/@appium/base-driver/node_modules/axios": { + "version": "1.7.7", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz", + "integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==", + "license": "MIT", + "dependencies": { + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, "node_modules/@appium/base-driver/node_modules/brace-expansion": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", @@ -1470,6 +1481,18 @@ "node": ">=8.0.0" } }, + "node_modules/@appium/base-plugin/node_modules/axios": { + "version": "1.7.7", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz", + "integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==", + "license": "MIT", + "peer": true, + "dependencies": { + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, "node_modules/@appium/base-plugin/node_modules/brace-expansion": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", @@ -2342,6 +2365,18 @@ "node": ">=8.0.0" } }, + "node_modules/@appium/docutils/node_modules/axios": { + "version": "1.7.7", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz", + "integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==", + "license": "MIT", + "peer": true, + "dependencies": { + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, "node_modules/@appium/docutils/node_modules/brace-expansion": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", @@ -2751,16 +2786,6 @@ "npm": ">=8" } }, - "node_modules/@appium/support/node_modules/axios": { - "version": "1.6.3", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.3.tgz", - "integrity": "sha512-fWyNdeawGam70jXSVlKl+SUNVcL6j6W79CuSIPfi6HnDUmSCH6gyUys/HrqHeA/wU0Az41rRgean494d0Jb+ww==", - "dependencies": { - "follow-redirects": "^1.15.0", - "form-data": "^4.0.0", - "proxy-from-env": "^1.1.0" - } - }, "node_modules/@appium/support/node_modules/type-fest": { "version": "4.9.0", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.9.0.tgz", @@ -5918,6 +5943,17 @@ "node": ">=8.0.0" } }, + "node_modules/appium-chromedriver/node_modules/axios": { + "version": "1.7.7", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz", + "integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==", + "license": "MIT", + "dependencies": { + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, "node_modules/appium-chromedriver/node_modules/brace-expansion": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", @@ -6753,6 +6789,18 @@ "node": ">=8.0.0" } }, + "node_modules/appium/node_modules/axios": { + "version": "1.7.7", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz", + "integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==", + "license": "MIT", + "peer": true, + "dependencies": { + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, "node_modules/appium/node_modules/brace-expansion": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", @@ -7357,11 +7405,11 @@ } }, "node_modules/axios": { - "version": "1.7.7", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz", - "integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==", + "version": "1.6.3", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.3.tgz", + "integrity": "sha512-fWyNdeawGam70jXSVlKl+SUNVcL6j6W79CuSIPfi6HnDUmSCH6gyUys/HrqHeA/wU0Az41rRgean494d0Jb+ww==", "dependencies": { - "follow-redirects": "^1.15.6", + "follow-redirects": "^1.15.0", "form-data": "^4.0.0", "proxy-from-env": "^1.1.0" } From 8dfa78fa1cbd24c4754ca33ccff055515e784d73 Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Tue, 22 Oct 2024 22:19:30 -0700 Subject: [PATCH 17/19] Update README.md --- README.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7f6e8a99..539615c9 100644 --- a/README.md +++ b/README.md @@ -84,14 +84,20 @@ this driver supports the following: This script is used to install the given or latest stable version of chromedriver (113+) from [Chrome for testing](https://github.com/GoogleChromeLabs/chrome-for-testing) with `appium driver run chromium install-chromedriver`. +Please read [Version selection](https://developer.chrome.com/docs/chromedriver/downloads/version-selection) document +to find a proper chromedriver manually that is good for your current browser. Below environment arguments are available: - `CHROMEDRIVER_EXECUTABLE_DIR` - - Let the command to download chromedrivers in the given directory. Once you set `appium:executableDir` to the same directory, a new session will refer to the same directory. Defaults to `node_modules/appium-chromedriver/chromedriver` in `appium-chromium-driver` package. - - `CHROMEDRIVER_EXECUTABLE_DIR=/tmp/chromedrivers appium driver run chromium install-chromedriver` + - Let the command to download chromedrivers in the given directory. Defaults to `node_modules/appium-chromedriver/chromedriver` in `appium-chromium-driver` package. + - i.e. + - macOS/Linux: `CHROMEDRIVER_EXECUTABLE_DIR=/path/to/dir appium driver run chromium install-chromedriver` + - Windows: `$env:CHROMEDRIVER_EXECUTABLE_DIR='C:\path\to\folder'; appium driver run chromium install-chromedriver; Remove-Item Env:\CHROMEDRIVER_EXECUTABLE_DIR` - `CHROMEDRIVER_VERSION` - Let the command download a specific version. - - i.e. `CHROMEDRIVER_VERSION=131.0.6778.3 appium driver run chromium install-chromedriver` + - i.e. + - macOS/Linux: `CHROMEDRIVER_VERSION=131.0.6778.3 appium driver run chromium install-chromedriver` + - Windows: `$env:CHROMEDRIVER_VERSION='131.0.6778.3'; appium driver run chromium install-chromedriver; Remove-Item Env:\CHROMEDRIVER_VERSION` - `CHROMELABS_URL` - Let the command get the list of available chromedrivers from instead of the default `https://googlechromelabs.github.io`. From e17a84f59d8a041c3cbf1c66a2c32dad8d2fb5e3 Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Tue, 22 Oct 2024 22:22:55 -0700 Subject: [PATCH 18/19] run npm install again --- package-lock.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index a62122ae..e17fe59f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "appium-chromium-driver", - "version": "1.3.56", + "version": "1.3.57", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "appium-chromium-driver", - "version": "1.3.56", + "version": "1.3.57", "license": "Apache-2.0", "dependencies": { "appium-chromedriver": "^6.1.0", From 0a1cd73babc20abc3ee30ab91546ca34761189be Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Wed, 23 Oct 2024 00:20:58 -0700 Subject: [PATCH 19/19] reflect review --- .eslintrc.json | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 84dc8845..799195d1 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -8,7 +8,7 @@ } }, { - "files": "scripts/**/*", + "files": ["**/*.{mjs,cjs,js}"], "parserOptions": {"sourceType": "module"}, "rules": { "@typescript-eslint/no-var-requires": "off" diff --git a/README.md b/README.md index 539615c9..5b1634e2 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ Below environment arguments are available: - macOS/Linux: `CHROMEDRIVER_VERSION=131.0.6778.3 appium driver run chromium install-chromedriver` - Windows: `$env:CHROMEDRIVER_VERSION='131.0.6778.3'; appium driver run chromium install-chromedriver; Remove-Item Env:\CHROMEDRIVER_VERSION` - `CHROMELABS_URL` - - Let the command get the list of available chromedrivers from instead of the default `https://googlechromelabs.github.io`. + - Let the command get the list of available chromedrivers from the given mirror instead of the default one. ## Contributing