Skip to content

Commit f094133

Browse files
authored
Update index.js
Fix race condition!
1 parent 03fbccf commit f094133

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

javascript/selenium-webdriver/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,10 +680,14 @@ class Builder {
680680
if (this.firefoxService_) {
681681
service = this.firefoxService_.build()
682682
}
683+
684+
// Find a free port before starting Firefox
685+
const port = portprober.findFreePort();
686+
683687
// Allocate a free port for the websocket only when not connecting to an existing instance
684688
// This avoids conflicts when multiple Firefox instances have started
685689
if (!service?.options_.args.includes('--connect-existing')) {
686-
service?.addArguments('--websocket-port', `${portprober.findFreePort()}`)
690+
service?.addArguments('--websocket-port', `${port}`)
687691
}
688692
return createDriver(firefox.Driver, capabilities, service)
689693
}

0 commit comments

Comments
 (0)