From 6079f2776620e734edbeac7f079ce20376710eae Mon Sep 17 00:00:00 2001 From: Delta456 Date: Wed, 26 Mar 2025 16:09:33 +0530 Subject: [PATCH 1/5] [js] add --websocket-port flag when not connecting to existing connection on firefox --- javascript/selenium-webdriver/index.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/javascript/selenium-webdriver/index.js b/javascript/selenium-webdriver/index.js index 962b30c655bec..052dbe0224307 100644 --- a/javascript/selenium-webdriver/index.js +++ b/javascript/selenium-webdriver/index.js @@ -44,6 +44,7 @@ const BrowsingContext = require('./bidi/browsingContext') const BrowsingContextInspector = require('./bidi/browsingContextInspector') const ScriptManager = require('./bidi/scriptManager') const NetworkInspector = require('./bidi/networkInspector') +const portprober = require('./net/portprober') const version = require('./package.json').version const Browser = capabilities.Browser @@ -679,6 +680,12 @@ class Builder { if (this.firefoxService_) { service = this.firefoxService_.build() } + // Allocate a free port for the websocket only when not connecting to an existing instance + // This avoids conflicts when multiple Firefox instances have started + if (!service?.args.includes('--connect-existing')) { + service?.args.append('--websocket-port') + service?.args.append(`${portprober.findFreePort()}`) + } return createDriver(firefox.Driver, capabilities, service) } From cc11dd55fb97f2318697adac54dcaf7a2c290edf Mon Sep 17 00:00:00 2001 From: Delta456 Date: Wed, 26 Mar 2025 16:15:27 +0530 Subject: [PATCH 2/5] use correct method --- javascript/selenium-webdriver/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/javascript/selenium-webdriver/index.js b/javascript/selenium-webdriver/index.js index 052dbe0224307..0428cea3a824e 100644 --- a/javascript/selenium-webdriver/index.js +++ b/javascript/selenium-webdriver/index.js @@ -683,8 +683,8 @@ class Builder { // Allocate a free port for the websocket only when not connecting to an existing instance // This avoids conflicts when multiple Firefox instances have started if (!service?.args.includes('--connect-existing')) { - service?.args.append('--websocket-port') - service?.args.append(`${portprober.findFreePort()}`) + service?.args.push('--websocket-port') + service?.args.push(`${portprober.findFreePort()}`) } return createDriver(firefox.Driver, capabilities, service) } From de2005116da4c895ac1b823e8d749173df1f39bf Mon Sep 17 00:00:00 2001 From: Delta456 Date: Wed, 26 Mar 2025 16:50:35 +0530 Subject: [PATCH 3/5] fix code --- javascript/selenium-webdriver/index.js | 5 ++--- javascript/selenium-webdriver/remote/index.js | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/javascript/selenium-webdriver/index.js b/javascript/selenium-webdriver/index.js index 0428cea3a824e..97f9270b3a9bc 100644 --- a/javascript/selenium-webdriver/index.js +++ b/javascript/selenium-webdriver/index.js @@ -682,9 +682,8 @@ class Builder { } // Allocate a free port for the websocket only when not connecting to an existing instance // This avoids conflicts when multiple Firefox instances have started - if (!service?.args.includes('--connect-existing')) { - service?.args.push('--websocket-port') - service?.args.push(`${portprober.findFreePort()}`) + if (!service?.options_.args.includes('--connect-existing')) { + service?.addArguments('--websocket-port', `${portprober.findFreePort()}`) } return createDriver(firefox.Driver, capabilities, service) } diff --git a/javascript/selenium-webdriver/remote/index.js b/javascript/selenium-webdriver/remote/index.js index bc3e4e3255696..79123db01680d 100644 --- a/javascript/selenium-webdriver/remote/index.js +++ b/javascript/selenium-webdriver/remote/index.js @@ -314,7 +314,7 @@ DriverService.DEFAULT_START_TIMEOUT_MS = 30 * 1000 */ DriverService.Builder = class { /** - * @param {string} exe Path to the executable to use. This executable must + * @param {string} exex Path to the executable to use. This executable must * accept the `--port` flag for defining the port to start the server on. * @throws {Error} If the provided executable path does not exist. */ From ff17596c0bccdc672cc33a50243d1e8b49c0a537 Mon Sep 17 00:00:00 2001 From: Sri Harsha <12621691+harsha509@users.noreply.github.com> Date: Fri, 28 Mar 2025 11:19:36 +0100 Subject: [PATCH 4/5] fix typo --- javascript/selenium-webdriver/remote/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javascript/selenium-webdriver/remote/index.js b/javascript/selenium-webdriver/remote/index.js index 79123db01680d..bc3e4e3255696 100644 --- a/javascript/selenium-webdriver/remote/index.js +++ b/javascript/selenium-webdriver/remote/index.js @@ -314,7 +314,7 @@ DriverService.DEFAULT_START_TIMEOUT_MS = 30 * 1000 */ DriverService.Builder = class { /** - * @param {string} exex Path to the executable to use. This executable must + * @param {string} exe Path to the executable to use. This executable must * accept the `--port` flag for defining the port to start the server on. * @throws {Error} If the provided executable path does not exist. */ From f0941331421791f2f44c7e1dce9d19d8bfa9581e Mon Sep 17 00:00:00 2001 From: Sri Harsha <12621691+harsha509@users.noreply.github.com> Date: Sun, 30 Mar 2025 16:30:34 -0400 Subject: [PATCH 5/5] Update index.js Fix race condition! --- javascript/selenium-webdriver/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/javascript/selenium-webdriver/index.js b/javascript/selenium-webdriver/index.js index 97f9270b3a9bc..bd06bcdc0f261 100644 --- a/javascript/selenium-webdriver/index.js +++ b/javascript/selenium-webdriver/index.js @@ -680,10 +680,14 @@ class Builder { if (this.firefoxService_) { service = this.firefoxService_.build() } + + // Find a free port before starting Firefox + const port = portprober.findFreePort(); + // Allocate a free port for the websocket only when not connecting to an existing instance // This avoids conflicts when multiple Firefox instances have started if (!service?.options_.args.includes('--connect-existing')) { - service?.addArguments('--websocket-port', `${portprober.findFreePort()}`) + service?.addArguments('--websocket-port', `${port}`) } return createDriver(firefox.Driver, capabilities, service) }