Adding second instance of Firefox with Marionette (change port)

Question:

I’m having great difficulties creating two instances of firefox via marionette. Having one instance works fine:

Starting up Firefox with marionette enabled:

firefox.exe -marionette

Controlling it with python:

from marionette import Marionette
client = Marionette('localhost', port=2828)
client.start_session()
client.execute_script("alert('o hai there!');")

Now I’d like to add a second client alongside the current one, a quick search resulted in the –address command:

firefox.exe -marionette --address=localhost:2829

Trying to control it via python:

from marionette import Marionette
client = Marionette('localhost', port=2829)
client.start_session()
client.execute_script("alert('o hai there!');")

I can’t seem to get this to work, however:

error: [Errno 10061] No connection could be made because the target machine actively refused it

Any help is greatly appreciated.

Asked By: MattV

||

Answers:

You have to use different profiles to make firefox listen on different ports.
Edit <path-to-profile>/prefs.js add the following and save when firefox is not using this profile;

user_pref("marionette.defaultPrefs.port", 2829);

Now, start firefox as;

firefox -marionette --profile <path-to-profile> --new-instance&

To create a new profile;

$ mkdir new_profile
$ firefox --profile new_profile --new-instance

and close firefox. Now you’ll have new_profile/prefs.js

Answered By: Nizam Mohamed

It’s been a while since the previous reply, so a small update

For now (Firefox version 103+) preference have to be set is called

marionette.port

so, you have to set

user_pref("marionette.port", 2829);

All procedure looks like:

$ firefox -CreateProfile "p2829 /tmp/ff_p2829"
$ vi /tmp/ff_p2829/prefs.js #new file
  > enter user_pref("marionette.port", 2829); 
$ firefox -marionette -profile /tmp/ff_p2829/ -new-instance

and now firefox marionette server listening on port 2829

Answered By: DrafFter