Skip to content

Commit

Permalink
Make new binaries url configurable
Browse files Browse the repository at this point in the history
Closes #417
  • Loading branch information
giggio committed Jul 18, 2023
1 parent 2f3d61d commit 33df5e5
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 35 deletions.
63 changes: 39 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ force it always download by configuring it:
npm install chromedriver --chromedriver-force-download
```

Or add property into your [`.npmrc`](https://docs.npmjs.com/files/npmrc) file.
Or add property to your [`.npmrc`](https://docs.npmjs.com/files/npmrc) file.

```
```ini
chromedriver_force_download=true
```

Expand All @@ -50,41 +50,56 @@ CHROMEDRIVER_FORCE_DOWNLOAD=true npm install chromedriver

## Custom binaries url

This was changed for version 115 and greater, but implemented in this package starting with version
This allows you to use your own endpoints for metadata and binaries. It is useful in air gapped
scenarios or if you have download restrictions, such as firewalls.

This was changed for version 115 and greater
([see details](https://groups.google.com/g/chromedriver-users/c/clpipqvOGjE)),
but implemented in this package starting with version
`114.0.2`. To see the configuration to prior versions check out this
[README.md](https://github.com/giggio/node-chromedriver/tree/114.0.1#custom-binaries-url).
[README.md](https://github.com/giggio/node-chromedriver/tree/114.0.1#custom-binaries-url)
at the latest tag where it was using the legacy urls (`114.0.1`).

### For versions >= 115

To use a mirror of the ChromeDriver binaries use npm config property `chromedriver_cdnurl`.
Default is `https://googlechromelabs.github.io`.
There are two urls that need to be configured, one for metadata and one for binaries.
The one for metadata is the "CDN url", and the one for binaries is the "CDN binaries url".
See [Chrome for Testing](https://googlechromelabs.github.io/chrome-for-testing/) to understand
how these urls work.

Npm config:
For metadata use `chromedriver_cdnurl`. The default is `https://googlechromelabs.github.io`.
For binaries use `chromedriver_cdnurl`. The default is `https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing`.

```shell
npm install chromedriver --chromedriver_cdnurl=https://npmmirror.com/mirrors/chromedriver
npm install chromedriver --chromedriver_cdnurl=https://npmmirror.com/metadata --chromedriver_cdnbinariesurl=https://npmmirror.com/binaries
```

Or add a property into your [`.npmrc`](https://docs.npmjs.com/files/npmrc) file:
Or add these properties to your [`.npmrc`](https://docs.npmjs.com/cli/configuring-npm/npmrc) file:

```ini
chromedriver_cdnurl=https://npmmirror.com/mirrors/chromedriver
chromedriver_cdnurl=https://npmmirror.com/metadata
chromedriver_cdnbinariesurl=https://npmmirror.com/binaries
```

Another option is to use the environment variable `CHROMEDRIVER_CDNURL`.
Another option is to use the environment variables `CHROMEDRIVER_CDNURL` and `CHROMEDRIVER_CDNBINARIESURL`.

```shell
CHROMEDRIVER_CDNURL=https://npmmirror.com/mirrors/chromedriver npm install chromedriver
CHROMEDRIVER_CDNURL=https://npmmirror.com/metadata CHROMEDRIVER_CDNBINARIESURL=https://npmmirror.com/binaries npm install chromedriver
```

### For versions < 115

There is one url to both metadata and binaries.

To use a mirror of the ChromeDriver binaries use npm config property `chromedriver_legacy_cdnurl`.
Default is `https://chromedriver.storage.googleapis.com`.

```shell
npm install chromedriver --chromedriver_legacy_cdnurl=https://npmmirror.com/mirrors/chromedriver
npm install chromedriver --chromedriver_legacy_cdnurl=https://npmmirror.com/mirrors/chromedriver --chromedriver_version=LATEST_114
```

Or add a property into your [`.npmrc`](https://docs.npmjs.com/files/npmrc) file:
Or add a property to your [`.npmrc`](https://docs.npmjs.com/files/npmrc) file:

```ini
chromedriver_legacy_cdnurl=https://npmmirror.com/mirrors/chromedriver
Expand All @@ -93,7 +108,7 @@ chromedriver_legacy_cdnurl=https://npmmirror.com/mirrors/chromedriver
Another option is to use the environment variable `CHROMEDRIVER_LEGACY_CDNURL`.

```shell
CHROMEDRIVER_LEGACY_CDNURL=https://npmmirror.com/mirrors/chromedriver npm install chromedriver
CHROMEDRIVER_LEGACY_CDNURL=https://npmmirror.com/mirrors/chromedriver npm install chromedriver --chromedriver_version=LATEST_114
```

## Custom binaries file
Expand All @@ -104,9 +119,9 @@ To get the chromedriver from the filesystem instead of a web request use the npm
npm install chromedriver --chromedriver_filepath=/path/to/chromedriver_mac64.zip
```

Or add property into your [`.npmrc`](https://docs.npmjs.com/files/npmrc) file.
Or add property to your [`.npmrc`](https://docs.npmjs.com/files/npmrc) file.

```
```ini
chromedriver_filepath=/path/to/chromedriver_mac64.zip
```

Expand Down Expand Up @@ -147,9 +162,9 @@ To achieve this you can use the npm config property `chromedriver_skip_download`
npm install chromedriver --chromedriver_skip_download=true
```

Or add property into your [`.npmrc`](https://docs.npmjs.com/files/npmrc) file.
Or add property to your [`.npmrc`](https://docs.npmjs.com/files/npmrc) file.

```
```ini
chromedriver_skip_download=true
```

Expand Down Expand Up @@ -245,9 +260,9 @@ use `LATEST` as the version number:
npm install chromedriver --chromedriver_version=LATEST
```

Or add property into your [`.npmrc`](https://docs.npmjs.com/files/npmrc) file.
Or add property to your [`.npmrc`](https://docs.npmjs.com/files/npmrc) file.

```
```ini
chromedriver_version=LATEST
```

Expand Down Expand Up @@ -279,9 +294,9 @@ you can use the npm config property `detect_chromedriver_version`.
npm install chromedriver --detect_chromedriver_version
```

Or add property into your [`.npmrc`](https://docs.npmjs.com/files/npmrc) file.
Or add property to your [`.npmrc`](https://docs.npmjs.com/files/npmrc) file.

```
```ini
detect_chromedriver_version=true
```

Expand All @@ -302,9 +317,9 @@ If you don't have Chrome installed, you can check for Chromium version instead b
npm install chromedriver --include_chromium
```

Or add property into your [`.npmrc`](https://docs.npmjs.com/files/npmrc) file.
Or add property to your [`.npmrc`](https://docs.npmjs.com/files/npmrc) file.

```
```ini
include_chromium=true
```

Expand Down
12 changes: 5 additions & 7 deletions install.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ if (skipDownload) {
}

(async function install() {
let cdnUrl = process.env.npm_config_chromedriver_cdnurl || process.env.CHROMEDRIVER_CDNURL || 'https://googlechromelabs.github.io';
const legacyCdnUrl = process.env.npm_config_chromedriver_legacy_cdnurl || process.env.CHROMEDRIVER_LEGACY_CDNURL || 'https://chromedriver.storage.googleapis.com';
// adapt http://chromedriver.storage.googleapis.com/
cdnUrl = cdnUrl.replace(/\/+$/, '');
const cdnUrl = (process.env.npm_config_chromedriver_cdnurl || process.env.CHROMEDRIVER_CDNURL || 'https://googlechromelabs.github.io').replace(/\/+$/, '');
const legacyCdnUrl = (process.env.npm_config_chromedriver_legacy_cdnurl || process.env.CHROMEDRIVER_LEGACY_CDNURL || 'https://chromedriver.storage.googleapis.com').replace(/\/+$/, '');
let chromedriverVersion = process.env.npm_config_chromedriver_version || process.env.CHROMEDRIVER_VERSION || helper.version;
const detectChromedriverVersion = (process.env.npm_config_detect_chromedriver_version || process.env.DETECT_CHROMEDRIVER_VERSION) === 'true';
try {
Expand Down Expand Up @@ -65,7 +63,8 @@ if (skipDownload) {
const chromedriverIsAvailable = await verifyIfChromedriverIsAvailableAndHasCorrectVersion(chromedriverVersion, chromedriverBinaryFilePath);
if (!chromedriverIsAvailable) {
console.log('Current existing ChromeDriver binary is unavailable, proceeding with download and extraction.');
await downloadFile(useLegacyMethod ? legacyCdnUrl : cdnUrl, useLegacyMethod, downloadedFile, chromedriverVersion, platform, detectChromedriverVersion);
const cdnBinariesUrl = (process.env.npm_config_chromedriver_cdnbinariesurl || process.env.CHROMEDRIVER_CDNBINARIESURL || 'https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing').replace(/\/+$/, '');
await downloadFile(useLegacyMethod ? legacyCdnUrl : cdnBinariesUrl, useLegacyMethod, downloadedFile, chromedriverVersion, platform, detectChromedriverVersion);
await extractDownload(extractDirectory, chromedriverBinaryFilePath, downloadedFile);
}
const libPath = path.join(__dirname, 'lib', 'chromedriver');
Expand Down Expand Up @@ -130,8 +129,7 @@ async function downloadFile(cdnUrl, useLegacyDownloadMethod, downloadedFile, chr
console.log('Downloading from file: ', formattedDownloadUrl);
await requestBinary(getRequestOptions(formattedDownloadUrl), downloadedFile);
} else {
const dlBaseUrl = 'https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing'; // todo: make this configurable?
const formattedDownloadUrl = `${dlBaseUrl}/${chromedriverVersion}/${platform}/${fileName}`;
const formattedDownloadUrl = `${cdnUrl}/${chromedriverVersion}/${platform}/${fileName}`;
console.log('Downloading from file: ', formattedDownloadUrl);
await requestBinary(getRequestOptions(formattedDownloadUrl), downloadedFile);
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chromedriver",
"version": "114.0.2",
"version": "114.0.3",
"keywords": [
"chromedriver",
"selenium"
Expand Down Expand Up @@ -43,4 +43,4 @@
"engines": {
"node": ">=16"
}
}
}

0 comments on commit 33df5e5

Please sign in to comment.