@@ -222,13 +222,26 @@ protected List<String> createArgs() {
222222 List <String > args = new ArrayList <>();
223223 args .add (String .format (Locale .ROOT , "--port=%d" , getPort ()));
224224
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+ }
227233
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+ }
232245
233246 if (logLevel != null ) {
234247 args .add ("--log" );
0 commit comments