giggio / node-chromedriver

An installer and wrapper for Chromedriver.
Apache License 2.0
477 stars 182 forks source link

Unable to install from pre-installed binary #424

Closed tpodom closed 1 year ago

tpodom commented 1 year ago

Hi, starting with version 14.0.3, we have been running into issues when installing the chromedriver package. Our docker image has the chromedriver binary pre-installed and we configure CHROMEDRIVER_FILEPATH but it looks like this change is causing the install to attempt to download which fails because we don't have access to the CDN URLs. We tried setting DETECT_CHROMEDRIVER_VERSION to allow that if condition to be true but that then causes a different failure trying to fetch LATEST_RELEASE_<version> from the CDN.

I wasn't sure if the change in downloadFile was intentional or not?

In the past, we tried to set CHROMEDRIVER_SKIP_DOWNLOAD but that then seemed to cause problems with wide because the binary wasn't in node_modules/chromedriver/lib/chromedriver

dnoliver commented 1 year ago

Same issue here while trying to npm install chromedriver. Version detected is 115.0.5790. There is no chromedriver yet for such version in https://chromedriver.chromium.org/downloads

Changed my .npmrc to use latest instead of detected version:

$ git diff .npmrc
diff --git a/.npmrc b/.npmrc
index e74f974..da63927 100644
--- a/.npmrc
+++ b/.npmrc
@@ -4,4 +4,5 @@

 # See https://github.com/giggio/node-chromedriver#detect-chromedriver-version
 # Uncomment the following option to use the chromedriver that correspond to the chrome version installed
-detect_chromedriver_version=true
+detect_chromedriver_version=false
+chromedriver_version=LATEST

installation worked. and my tests are functional again.

There is an announcement about this back in May 2023, that the chrome people were changing the release process of chromedrivers: https://groups.google.com/g/chromedriver-users/c/clpipqvOGjE?pli=1

Latest drivers are available at https://googlechromelabs.github.io/chrome-for-testing/.

jan-molak commented 1 year ago

I also see issues with CHROMEDRIVER_FILEPATH not being considered.

For example, GitHub Actions runners are always slightly behind the latest version (e.g. 115 while the latest is 116, at the time of writing).

GitHub Actions have the chromedriver binary pre-installed at $CHROMEWEBDRIVER/chromedriver:

CHROMEDRIVER_FILEPATH="$CHROMEWEBDRIVER/chromedriver"

echo $CHROMEDRIVER_FILEPATH
/usr/local/share/chromedriver-linux64/chromedriver

However, even with CHROMEDRIVER_FILEPATH pointing to the local binary, it looks like chromedriver module downloads the latest version regardless:

Error: SessionNotCreatedError: session not created: This version of ChromeDriver only supports Chrome version 116
[test:acceptance] Current browser version is 115.0.5790.170 with binary path /opt/google/chrome/chrome
[test:acceptance]   (Driver info: chromedriver=116.0.5845.96 (1a391816688002153ef791ffe60d9e899a71a037-refs/branch-heads/5845@{#1382}),platform=Linux 5.15.0-1042-azure x86_64)
dnoliver commented 1 year ago

@jan-molak I got the chromedriver package using the custom file working.

Downloaded chromedriver 16:

curl -O https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/116.0.5845.96/win64/chromedriver-win64.zip

Then set my .npmrc to this:

detect_chromedriver_version=false
chromedriver_filepath=C:\Users\dnoliver\<redacted>\chromedriver-win64.zip

Then running npm install again told me the following:

$ npm install 

> chromedriver@104.0.0 install C:\Users\dnoliver\<redacted>\node_modules\chromedriver
> node install.js

Current existing ChromeDriver binary is unavailable, proceeding with download and extraction.
Using file:  C:\Users\dnoliver\<redacted>\chromedriver-win64.zip
Extracting zip contents to C:\Users\dnoliver\AppData\Local\Temp\104.0.5112.79\chromedriver.
Copying from C:\Users\dnoliver\AppData\Local\Temp\104.0.5112.79\chromedriver to target path C:\Users\dnoliver\<redacted>\node_modules\chromedriver\lib\chromedriver
Done. ChromeDriver binary available at C:\Users\dnoliver\<redacted>\node_modules\chromedriver\lib\chromedriver\chromedriver.exe
npm WARN @mochajs/json-file-reporter@1.3.0 requires a peer of mocha@6.x || 7.x || 8.x but none is installed. You must install peer dependencies yourself.
npm WARN <redacted>@1.0.0 No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

added 29 packages from 21 contributors and audited 438 packages in 2.02s

62 packages are looking for funding
  run `npm fund` for details

found 3 moderate severity vulnerabilities
  run `npm audit fix` to fix them, or `npm audit` for details

But I ended up with an empty node_modules/chromedriver/lib/chromedriver/ folder. Then I just copied the binary from the Temp path into my node modules folder, and I updated my PATH env var to include the node modules folder (I do it in vscode launch.jsos as this is how I usually run my tests):

"PATH": "${workspaceFolder}/node_modules/chromedriver/lib/chromedriver:${env:PATH}"

And then I can launch tests from vscode, I guess the same fix applies to a regular terminal.

Ugly workaround but acceptable Friday solution for me :)

giggio commented 1 year ago

I believe this was fixed when we updated the code to use Chrome for Testing. Are you still experiencing the problem?

tpodom commented 1 year ago

@giggio yes, we have not been able to figure out a clean workaround for this issue. There does not seem to be any way for us to perform an install using just our NPM proxy and no other external internet access.

The code as it stands right now, requires detect_chromedriver_version=true to use the configured chrome driver file path:

 if (detectChromedriverVersion && configuredfilePath) {
    console.log('Using file: ', configuredfilePath);
    return configuredfilePath;
  } 

However, if we set detect_chromedriver_version=true it then tries to reach out to the internet to download metadata to find the chromedriver version. If we set it to false, the configured file path is ignored.

giggio commented 1 year ago

@tpodom yes, I have just confirmed the bug. I have to check why detectChromedriverVersion is in there, but I have confirmed that it is not working as expected.

giggio commented 1 year ago

It turns out the check for detectChromedriverVersion was not supposed to be there. It was probably left over from some previous change. I have removed it and fixed another issue I found with the download. I'll publish it as 117.0.1 as soon as the build passes.

github-actions[bot] commented 1 year ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.