Giter Site home page Giter Site logo

Comments (11)

alexsch01 avatar alexsch01 commented on June 8, 2024 12

@thw0rted

If you have Protractor installed globally via npm on Windows 64-bit, you can use these steps


%APPDATA%\npm\node_modules\protractor\node_modules\webdriver-manager\built\lib\binaries\chrome_xml.js

  • Replace getLatestChromeDriverVersion function with:
getLatestChromeDriverVersion() {
        const path = require('path')
        const fs = require('fs')

        const lastKnownGoodVersionsWithDownloads_Url = 'https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json';
        return http_utils_1.requestBody(lastKnownGoodVersionsWithDownloads_Url).then(body => {
            const latestVersion_Body = JSON.parse(body)['channels']['Stable']

            const latestVersion = latestVersion_Body['version']
            const latestVersion_Url = latestVersion_Body['downloads']['chromedriver'].find(obj => obj['platform'] == 'win32')['url']

            const latestMajorVersion = latestVersion.split('.')[0]

            const localVersion_FileName = fs.readdirSync(path.resolve(__dirname, '..', '..', '..', 'selenium'))
                .find(f => f.startsWith(`chromedriver_${latestMajorVersion}`)) || ''
                
            const localVersion = localVersion_FileName.slice(13, -4)
            const localVersion_Url = latestVersion_Url.replace(latestVersion, localVersion)

            const localMajorVersion = localVersion.split('.')[0]

            if (latestMajorVersion == localMajorVersion) {
                return Promise.resolve({
                    url: localVersion_Url,
                    version: localVersion,
                })
            } else {
                return Promise.resolve({
                    url: latestVersion_Url,
                    version: latestVersion,
                })
            }
        });
    }

%APPDATA%\npm\node_modules\protractor\node_modules\webdriver-manager\built\lib\cmds\update.js

  • Replace line 240 [fs.renameSync(path.resolve(outputDir, binary.zipContentName()), mv);] with:
if (fileName.indexOf('chromedriver_') != -1) {
        fs.renameSync(path.resolve(outputDir, 'chromedriver-win32', binary.zipContentName()), mv)
    } else {
        fs.renameSync(path.resolve(outputDir, binary.zipContentName()), mv);
    }

Finally, do a webdriver-manager update - it should get you to the next Chromedriver major version

from webdriver-manager.

DavidDudson avatar DavidDudson commented on June 8, 2024 3

For anyone who uses patch-package, this is a cross platform patch based on the above. (This assumes a non-global install)

Put it in a file named webdriver-manager+12.1.9.patch.

diff --git a/node_modules/webdriver-manager/built/lib/binaries/chrome_xml.js b/node_modules/webdriver-manager/built/lib/binaries/chrome_xml.js
index 6dfbea5..58bc44b 100644
--- a/node_modules/webdriver-manager/built/lib/binaries/chrome_xml.js
+++ b/node_modules/webdriver-manager/built/lib/binaries/chrome_xml.js
@@ -55,14 +55,74 @@ class ChromeXml extends config_source_1.XmlConfigSource {
             return 'linux';
         }
     }
+
+    /**
+     * Based on 'https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json' platforms
+     */
+    getPlatformForDownload() {
+        const os = require('os')
+        const arch = os.arch()
+
+      console.log(os.platform(), os.arch())
+
+        switch (os.platform()) {
+          case 'darwin':
+            return arch === 'x64'? 'mac-x64' : 'mac-arm64'
+          case 'win32':
+            return arch === 'x64'? 'win64' : 'win32'
+          default:
+            return 'linux64'
+        }
+    }
+
     /**
      * Gets the latest item from the XML.
      */
     getLatestChromeDriverVersion() {
-        const latestReleaseUrl = 'https://chromedriver.storage.googleapis.com/LATEST_RELEASE';
-        return http_utils_1.requestBody(latestReleaseUrl).then(latestVersion => {
-            return this.getSpecificChromeDriverVersion(latestVersion);
-        });
+      const path = require('path')
+      const fs = require('fs')
+
+      const lastKnownGoodVersionsWithDownloads_Url = 'https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json';
+      return http_utils_1.requestBody(lastKnownGoodVersionsWithDownloads_Url).then(body => {
+        const latestVersion_Body = JSON.parse(body)['channels']['Stable']
+
+        const latestVersion = latestVersion_Body['version']
+        const platformForDownload = this.getPlatformForDownload()
+        const latestVersion_Url = latestVersion_Body['downloads']['chromedriver'].find(obj => obj['platform'] == platformForDownload)['url']
+
+        console.log("Platform", platformForDownload)
+        console.log("Latest Version", latestVersion)
+        console.log("Latest Version URL", latestVersion_Url)
+        const latestMajorVersion = latestVersion.split('.')[0]
+
+        console.log("Latest Major Version", latestMajorVersion)
+
+        const localVersion_FileName = fs.readdirSync(path.resolve(__dirname, '..', '..', '..', 'selenium'))
+          .find(f => f.startsWith(`chromedriver_${latestMajorVersion}`)) || ''
+
+
+        const localVersion = localVersion_FileName.split('_').at(-1)
+        const localVersion_Url = latestVersion_Url.replace(latestVersion, localVersion)
+
+        const localMajorVersion = localVersion.split('.')[0]
+
+        console.log("Local File Name", localVersion_FileName)
+        console.log("Local Version", localVersion)
+        console.log("Local Version Url", localVersion_Url)
+        console.log("Local Major Version", localMajorVersion)
+
+        if (latestMajorVersion == localMajorVersion) {
+          return Promise.resolve({
+            url: localVersion_Url,
+            version: localVersion,
+          })
+        } else {
+          return Promise.resolve({
+            url: latestVersion_Url,
+            version: latestVersion,
+          })
+        }
+      });
     }
     /**
      * Gets a specific item from the XML.
diff --git a/node_modules/webdriver-manager/built/lib/cmds/update.js b/node_modules/webdriver-manager/built/lib/cmds/update.js
index b98cdce..86f7709 100644
--- a/node_modules/webdriver-manager/built/lib/cmds/update.js
+++ b/node_modules/webdriver-manager/built/lib/cmds/update.js
@@ -16,6 +16,7 @@ const utils_1 = require("../utils");
 const Opt = require("./");
 const initialize_1 = require("./initialize");
 const opts_1 = require("./opts");
+const os = require('os')
 config_1.Config.runCommand = 'update';
 let logger = new cli_1.Logger('update');
 let prog = new cli_1.Program()
@@ -207,6 +208,26 @@ function updateBinary(binary, outputDir, proxy, ignoreSSL) {
         }
     });
 }
+
+/**
+ * Based on 'https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json' platforms
+ */
+function getPlatformForDownload() {
+  const os = require('os')
+  const arch = os.arch()
+
+  console.log(os.platform(), os.arch())
+
+  switch (os.platform()) {
+    case 'darwin':
+      return arch === 'x64'? 'mac-x64' : 'mac-arm64'
+    case 'win32':
+      return arch === 'x64'? 'win64' : 'win32'
+    default:
+      return 'linux64'
+  }
+}
+
 function unzip(binary, outputDir, fileName) {
     // remove the previously saved file and unzip it
     let osType = config_1.Config.osType();
@@ -222,8 +243,8 @@ function unzip(binary, outputDir, fileName) {
         }
     }
     // unzip the file
-    logger.info(binary.name + ': unzipping ' + fileName);
-    if (fileName.slice(-4) == '.zip') {
+  logger.info(binary.name + ': unzipping ' + fileName);
+  if (fileName.slice(-4) == '.zip') {
         try {
             let zip = new AdmZip(path.resolve(outputDir, fileName));
             zip.extractAllTo(outputDir, true);
@@ -237,7 +258,11 @@ function unzip(binary, outputDir, fileName) {
         child_process.spawnSync('tar', ['zxvf', path.resolve(outputDir, fileName), '-C', outputDir]);
     }
     // rename
+  if (fileName.indexOf('chromedriver_') != -1) {
+    fs.renameSync(path.resolve(outputDir, 'chromedriver-' + getPlatformForDownload(), binary.zipContentName()), mv)
+  } else {
     fs.renameSync(path.resolve(outputDir, binary.zipContentName()), mv);
+  }
     // set permissions
     if (osType !== 'Windows_NT') {
         logger.info(binary.name + ': setting permissions to 0755 for ' + mv);

from webdriver-manager.

StanislavKharchenko avatar StanislavKharchenko commented on June 8, 2024

As alternatives you can use new library provided by selenium team - selenium - manager

from webdriver-manager.

tambor81 avatar tambor81 commented on June 8, 2024

we have now a CVE-2023-28155 reporting a vulnerability on protractor.
Can these dependencies be updated to not use protractor or use any other vulnerable dependency ?

currently this is clearly shown on :

$ npm audit
# npm audit report

request  *
Severity: moderate
Server-Side Request Forgery in Request - https://github.com/advisories/GHSA-p8p7-x288-28g6
fix available via `npm audit fix --force`
Will install [email protected], which is a breaking change
node_modules/request
  webdriver-manager  *
  Depends on vulnerable versions of request
  node_modules/webdriver-manager
    protractor  >=4.0.0
    Depends on vulnerable versions of webdriver-manager
    node_modules/protractor
      @angular-devkit/build-angular  >=0.1100.0-next.0
      Depends on vulnerable versions of protractor
      node_modules/@angular-devkit/build-angular

4 moderate severity vulnerabilities

To address all issues (including breaking changes), run:
  npm audit fix --force

from webdriver-manager.

thw0rted avatar thw0rted commented on June 8, 2024

It sure looks like webdriver-manager is EOL along with PRotractor. See #524 -- unless 3rd party post-EOL support comes along, the answer to your question is no, the dependencies for webdriver-manager will not be updated. I guess you could always fork it to fix yourself? Or look into the alternative in the second comment here.

from webdriver-manager.

leroybm avatar leroybm commented on June 8, 2024

Thanks @alexsch01, this worked for me after replacing win32 to linux64 :)

from webdriver-manager.

bashbers avatar bashbers commented on June 8, 2024

@DavidDudson Thanks, that worked! The other solution didnt work for me on mac eventhough I changed win32 to mac-x64.

from webdriver-manager.

JordanRieger avatar JordanRieger commented on June 8, 2024

@thw0rted

If you have Protractor installed globally via npm on Windows 64-bit, you can use these steps

%APPDATA%\npm\node_modules\protractor\node_modules\webdriver-manager\built\lib\binaries\chrome_xml.js

* Replace `getLatestChromeDriverVersion` function with:
getLatestChromeDriverVersion() {
        const path = require('path')
        const fs = require('fs')

        const lastKnownGoodVersionsWithDownloads_Url = 'https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json';
        return http_utils_1.requestBody(lastKnownGoodVersionsWithDownloads_Url).then(body => {
            const latestVersion_Body = JSON.parse(body)['channels']['Stable']

            const latestVersion = latestVersion_Body['version']
            const latestVersion_Url = latestVersion_Body['downloads']['chromedriver'].find(obj => obj['platform'] == 'win32')['url']

            const latestMajorVersion = latestVersion.split('.')[0]

            const localVersion_FileName = fs.readdirSync(path.resolve(__dirname, '..', '..', '..', 'selenium'))
                .find(f => f.startsWith(`chromedriver_${latestMajorVersion}`)) || ''
                
            const localVersion = localVersion_FileName.slice(13, -4)
            const localVersion_Url = latestVersion_Url.replace(latestVersion, localVersion)

            const localMajorVersion = localVersion.split('.')[0]

            if (latestMajorVersion == localMajorVersion) {
                return Promise.resolve({
                    url: localVersion_Url,
                    version: localVersion,
                })
            } else {
                return Promise.resolve({
                    url: latestVersion_Url,
                    version: latestVersion,
                })
            }
        });
    }

%APPDATA%\npm\node_modules\protractor\node_modules\webdriver-manager\built\lib\cmds\update.js

* Replace line 240 [`fs.renameSync(path.resolve(outputDir, binary.zipContentName()), mv);`] with:
if (fileName.indexOf('chromedriver_') != -1) {
        fs.renameSync(path.resolve(outputDir, 'chromedriver-win32', binary.zipContentName()), mv)
    } else {
        fs.renameSync(path.resolve(outputDir, binary.zipContentName()), mv);
    }

Finally, do a webdriver-manager update - it should get you to the next Chromedriver major version

After making this patch, ChromeDriver updates to 118 (latest as of 2023-10-16), but then I get this error when I try to actually run a protractor test:

[17:35:56] E/launcher - Unable to create new service: ChromeDriverService
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'DW-1-NEW', ip: '10.12.135.101', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.16.1'
Driver info: driver.version: unknown

from webdriver-manager.

emmapatterson avatar emmapatterson commented on June 8, 2024

For anyone who uses patch-package, this is a cross platform patch based on the above. (This assumes a non-global install)

Put it in a file named webdriver-manager+12.1.9.patch.

diff --git a/node_modules/webdriver-manager/built/lib/binaries/chrome_xml.js b/node_modules/webdriver-manager/built/lib/binaries/chrome_xml.js
index 6dfbea5..58bc44b 100644
--- a/node_modules/webdriver-manager/built/lib/binaries/chrome_xml.js
+++ b/node_modules/webdriver-manager/built/lib/binaries/chrome_xml.js
@@ -55,14 +55,74 @@ class ChromeXml extends config_source_1.XmlConfigSource {
             return 'linux';
         }
     }
+
+    /**
+     * Based on 'https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json' platforms
+     */
+    getPlatformForDownload() {
+        const os = require('os')
+        const arch = os.arch()
+
+      console.log(os.platform(), os.arch())
+
+        switch (os.platform()) {
+          case 'darwin':
+            return arch === 'x64'? 'mac-x64' : 'mac-arm64'
+          case 'win32':
+            return arch === 'x64'? 'win64' : 'win32'
+          default:
+            return 'linux64'
+        }
+    }
+
     /**
      * Gets the latest item from the XML.
      */
     getLatestChromeDriverVersion() {
-        const latestReleaseUrl = 'https://chromedriver.storage.googleapis.com/LATEST_RELEASE';
-        return http_utils_1.requestBody(latestReleaseUrl).then(latestVersion => {
-            return this.getSpecificChromeDriverVersion(latestVersion);
-        });
+      const path = require('path')
+      const fs = require('fs')
+
+      const lastKnownGoodVersionsWithDownloads_Url = 'https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json';
+      return http_utils_1.requestBody(lastKnownGoodVersionsWithDownloads_Url).then(body => {
+        const latestVersion_Body = JSON.parse(body)['channels']['Stable']
+
+        const latestVersion = latestVersion_Body['version']
+        const platformForDownload = this.getPlatformForDownload()
+        const latestVersion_Url = latestVersion_Body['downloads']['chromedriver'].find(obj => obj['platform'] == platformForDownload)['url']
+
+        console.log("Platform", platformForDownload)
+        console.log("Latest Version", latestVersion)
+        console.log("Latest Version URL", latestVersion_Url)
+        const latestMajorVersion = latestVersion.split('.')[0]
+
+        console.log("Latest Major Version", latestMajorVersion)
+
+        const localVersion_FileName = fs.readdirSync(path.resolve(__dirname, '..', '..', '..', 'selenium'))
+          .find(f => f.startsWith(`chromedriver_${latestMajorVersion}`)) || ''
+
+
+        const localVersion = localVersion_FileName.split('_').at(-1)
+        const localVersion_Url = latestVersion_Url.replace(latestVersion, localVersion)
+
+        const localMajorVersion = localVersion.split('.')[0]
+
+        console.log("Local File Name", localVersion_FileName)
+        console.log("Local Version", localVersion)
+        console.log("Local Version Url", localVersion_Url)
+        console.log("Local Major Version", localMajorVersion)
+
+        if (latestMajorVersion == localMajorVersion) {
+          return Promise.resolve({
+            url: localVersion_Url,
+            version: localVersion,
+          })
+        } else {
+          return Promise.resolve({
+            url: latestVersion_Url,
+            version: latestVersion,
+          })
+        }
+      });
     }
     /**
      * Gets a specific item from the XML.
diff --git a/node_modules/webdriver-manager/built/lib/cmds/update.js b/node_modules/webdriver-manager/built/lib/cmds/update.js
index b98cdce..86f7709 100644
--- a/node_modules/webdriver-manager/built/lib/cmds/update.js
+++ b/node_modules/webdriver-manager/built/lib/cmds/update.js
@@ -16,6 +16,7 @@ const utils_1 = require("../utils");
 const Opt = require("./");
 const initialize_1 = require("./initialize");
 const opts_1 = require("./opts");
+const os = require('os')
 config_1.Config.runCommand = 'update';
 let logger = new cli_1.Logger('update');
 let prog = new cli_1.Program()
@@ -207,6 +208,26 @@ function updateBinary(binary, outputDir, proxy, ignoreSSL) {
         }
     });
 }
+
+/**
+ * Based on 'https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json' platforms
+ */
+function getPlatformForDownload() {
+  const os = require('os')
+  const arch = os.arch()
+
+  console.log(os.platform(), os.arch())
+
+  switch (os.platform()) {
+    case 'darwin':
+      return arch === 'x64'? 'mac-x64' : 'mac-arm64'
+    case 'win32':
+      return arch === 'x64'? 'win64' : 'win32'
+    default:
+      return 'linux64'
+  }
+}
+
 function unzip(binary, outputDir, fileName) {
     // remove the previously saved file and unzip it
     let osType = config_1.Config.osType();
@@ -222,8 +243,8 @@ function unzip(binary, outputDir, fileName) {
         }
     }
     // unzip the file
-    logger.info(binary.name + ': unzipping ' + fileName);
-    if (fileName.slice(-4) == '.zip') {
+  logger.info(binary.name + ': unzipping ' + fileName);
+  if (fileName.slice(-4) == '.zip') {
         try {
             let zip = new AdmZip(path.resolve(outputDir, fileName));
             zip.extractAllTo(outputDir, true);
@@ -237,7 +258,11 @@ function unzip(binary, outputDir, fileName) {
         child_process.spawnSync('tar', ['zxvf', path.resolve(outputDir, fileName), '-C', outputDir]);
     }
     // rename
+  if (fileName.indexOf('chromedriver_') != -1) {
+    fs.renameSync(path.resolve(outputDir, 'chromedriver-' + getPlatformForDownload(), binary.zipContentName()), mv)
+  } else {
     fs.renameSync(path.resolve(outputDir, binary.zipContentName()), mv);
+  }
     // set permissions
     if (osType !== 'Windows_NT') {
         logger.info(binary.name + ': setting permissions to 0755 for ' + mv);

Hey @DavidDudson ! thanks for this! can you post the code changes you made without the patch output?

Cheers!

I am seeing issues if you set the version in the cli (instead of using latest) but I am trying to solve this now 🤞

from webdriver-manager.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.