From 6afcf117548243db682bda2824976d321977d9b2 Mon Sep 17 00:00:00 2001 From: Sri Harsha Date: Wed, 2 Apr 2025 20:30:34 -0400 Subject: [PATCH 1/2] [JS] Add websocket port option in Firefox ServiceBuilder when '--connect-existing' is not passed --- javascript/selenium-webdriver/firefox.js | 26 ++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/javascript/selenium-webdriver/firefox.js b/javascript/selenium-webdriver/firefox.js index f6cd1cf1e9d7e..1f5bb958e26e2 100644 --- a/javascript/selenium-webdriver/firefox.js +++ b/javascript/selenium-webdriver/firefox.js @@ -121,6 +121,7 @@ const zip = require('./io/zip') const { Browser, Capabilities, Capability } = require('./lib/capabilities') const { Zip } = require('./io/zip') const { getBinaryPaths } = require('./common/driverFinder') +const { findFreePort } = require('./net/portprober') const FIREFOX_CAPABILITY_KEY = 'moz:firefoxOptions' /** @@ -505,6 +506,31 @@ class ServiceBuilder extends remote.DriverService.Builder { enableVerboseLogging(opt_trace) { return this.addArguments(opt_trace ? '-vv' : '-v') } + + /** + * Overrides the parent build() method to add the websocket port argument + * for Firefox when not connecting to an existing instance. + * + * @return {!DriverService} A new driver service instance. + */ + build() { + let port = this.options_.port || findFreePort(); + let argsPromise = Promise.resolve(port).then((port) => { + // Start with the default --port argument. + let args = this.options_.args.concat(`--port=${port}`); + // If the "--connect-existing" flag is not set, add the websocket port. + if (!this.options_.args.some(arg => arg === '--connect-existing')) { + return findFreePort().then(wsPort => { + args.push(`--websocket-port=${wsPort}`); + return args; + }); + } + return args; + }); + + let options = Object.assign({}, this.options_, { args: argsPromise, port }); + return new remote.DriverService(this.exe_, options); + } } /** From 4f8488c3471a5b08041b1292f582b703e92972e5 Mon Sep 17 00:00:00 2001 From: Sri Harsha Date: Wed, 2 Apr 2025 20:33:17 -0400 Subject: [PATCH 2/2] fix format --- javascript/selenium-webdriver/firefox.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/javascript/selenium-webdriver/firefox.js b/javascript/selenium-webdriver/firefox.js index 1f5bb958e26e2..1633646666078 100644 --- a/javascript/selenium-webdriver/firefox.js +++ b/javascript/selenium-webdriver/firefox.js @@ -514,22 +514,22 @@ class ServiceBuilder extends remote.DriverService.Builder { * @return {!DriverService} A new driver service instance. */ build() { - let port = this.options_.port || findFreePort(); + let port = this.options_.port || findFreePort() let argsPromise = Promise.resolve(port).then((port) => { // Start with the default --port argument. - let args = this.options_.args.concat(`--port=${port}`); + let args = this.options_.args.concat(`--port=${port}`) // If the "--connect-existing" flag is not set, add the websocket port. - if (!this.options_.args.some(arg => arg === '--connect-existing')) { - return findFreePort().then(wsPort => { - args.push(`--websocket-port=${wsPort}`); - return args; - }); + if (!this.options_.args.some((arg) => arg === '--connect-existing')) { + return findFreePort().then((wsPort) => { + args.push(`--websocket-port=${wsPort}`) + return args + }) } - return args; - }); + return args + }) - let options = Object.assign({}, this.options_, { args: argsPromise, port }); - return new remote.DriverService(this.exe_, options); + let options = Object.assign({}, this.options_, { args: argsPromise, port }) + return new remote.DriverService(this.exe_, options) } }