@@ -222,13 +222,26 @@ protected List<String> createArgs() {
222
222
List <String > args = new ArrayList <>();
223
223
args .add (String .format (Locale .ROOT , "--port=%d" , getPort ()));
224
224
225
- int wsPort = PortProber .findFreePort ();
226
- args .add (String .format ("--websocket-port=%d" , wsPort ));
225
+ // Check if we're connecting to an existing Firefox instance
226
+ boolean connectExisting = false ;
227
+ for (String arg : args ) {
228
+ if (arg .contains ("--connect-existing" )) {
229
+ connectExisting = true ;
230
+ break ;
231
+ }
232
+ }
227
233
228
- args .add ("--allow-origins" );
229
- args .add (String .format ("http://127.0.0.1:%d" , wsPort ));
230
- args .add (String .format ("http://localhost:%d" , wsPort ));
231
- args .add (String .format ("http://[::1]:%d" , wsPort ));
234
+ // Only allocate a free port for the websocket when not connecting to an existing instance
235
+ // This avoids conflicts when multiple Firefox instances are started
236
+ if (!connectExisting ) {
237
+ int wsPort = PortProber .findFreePort ();
238
+ args .add (String .format ("--websocket-port=%d" , wsPort ));
239
+
240
+ args .add ("--allow-origins" );
241
+ args .add (String .format ("http://127.0.0.1:%d" , wsPort ));
242
+ args .add (String .format ("http://localhost:%d" , wsPort ));
243
+ args .add (String .format ("http://[::1]:%d" , wsPort ));
244
+ }
232
245
233
246
if (logLevel != null ) {
234
247
args .add ("--log" );
0 commit comments