From 419149c1209e570d8176265036282b9d35188b0b Mon Sep 17 00:00:00 2001 From: Paul Grime Date: Tue, 31 Oct 2023 03:00:16 +0000 Subject: [PATCH] Chrome drivers 115+ (#105) Fixes #103. --- src/SeleniumTunnel.ts | 68 +++++++++++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 16 deletions(-) diff --git a/src/SeleniumTunnel.ts b/src/SeleniumTunnel.ts index a49192a..786fe9c 100644 --- a/src/SeleniumTunnel.ts +++ b/src/SeleniumTunnel.ts @@ -448,6 +448,13 @@ interface ChromeProperties { type ChromeOptions = Partial; +function versionGreaterThan(versionStr: String, version: number[]) { + const parts = String(versionStr).split('.').map(Number); + return version.some(function (part, i) { + return parts[i] > part; + }); +} + class ChromeConfig extends Config implements ChromeProperties, DriverFile @@ -456,19 +463,29 @@ class ChromeConfig baseUrl!: string; platform!: string; version!: string; + useNewDriverLocation!: boolean; constructor(options: ChromeOptions) { - super( - Object.assign( - { - arch: process.arch, - baseUrl: webdrivers.chrome.baseUrl, - platform: process.platform, - version: webdrivers.chrome.latest, - }, - options - ) + const opts = Object.assign( + { + arch: process.arch, + baseUrl: webdrivers.chrome.baseUrl, + platform: process.platform, + version: webdrivers.chrome.latest, + }, + options ); + + const useNewDriverLocation = versionGreaterThan(opts.version, [114]); + if (useNewDriverLocation && opts.baseUrl == webdrivers.chrome.baseUrl) { + // A 'new' chrome driver has been requested, but we're being asked to configure using the old default baseUrl. + // Therefore use new baseUrl for new driver instead. + opts.baseUrl = + 'https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing'; + } + + super(Object.assign(opts, options)); + this.useNewDriverLocation = useNewDriverLocation; } get artifact() { @@ -482,7 +499,10 @@ class ChromeConfig }); platform = isGreater ? 'mac64' : 'mac32'; } - return format('chromedriver_%s.zip', platform); + + return this.useNewDriverLocation + ? format('chromedriver-%s.zip', platform) + : format('chromedriver_%s.zip', platform); } get directory() { @@ -490,14 +510,30 @@ class ChromeConfig } get url() { - return format('%s/%s/%s', this.baseUrl, this.version, this.artifact); + return this.useNewDriverLocation + ? format( + '%s/%s/%s/%s', + this.baseUrl, + this.version, + this.platform, + this.artifact + ) + : format('%s/%s/%s', this.baseUrl, this.version, this.artifact); } get executable() { - return join( - this.directory, - this.platform === 'win32' ? 'chromedriver.exe' : 'chromedriver' - ); + return this.useNewDriverLocation + ? join( + this.directory, + format('chromedriver-%s', this.platform), + this.platform === 'win32' || this.platform === 'win64' + ? 'chromedriver.exe' + : 'chromedriver' + ) + : join( + this.directory, + this.platform === 'win32' ? 'chromedriver.exe' : 'chromedriver' + ); } get seleniumProperty() {