Friday, October 19, 2007


[ UPDATE 10/23 ]
A friend told me about the command line option -no-remote documented in that does the same thing the environment variable does. This is much more practical because it doesn't mess with the default configuration. I am still investigating why this option is called the way it is called and official and complete documentation

There is a wonderful feature for Firefox that allows to run several firefox processes, each with its own User Profile, in the same Windows/Linux. The keys to the multi-process/multi-profile firefox heaven is the environment variable 'MOZ_NO_REMOTE'.

Firefox (Mozilla) is capable of managing several user profiles. The same user may want to have several user profiles or may want to run simultaneously several Firefox processes:

  • Someone interested in testing different versions of Firefox may want to run them all at once to better compare.
  • Someone that uses a firefox profile stored in a flash thumb drive, so that he can have his same bookmarks, cookies, passords, etc, with him everywhere he goes, in any computer he uses.
  • Sometimes, he may not want to use a profile that contains cookies or passwords to visit other sites for security reasons.
So, it may be cool to have more than one user profile. And if it is possible to run several user profiles at once, then you can customize them in very interesting ways.

For instance, I have a user profile with numerous plugins installed, that I use when I want one of the features of the plugins, but I seldom use it because it is slow and clunky (too many plugins), so, I have a 'light' profile for most of my usage.

You may run several processes of Firefox simultaneously by setting the environment variable 'MOZ_NO_REMOTE' to one. In a DOS/Windows command line '.bat' file, you can do something like this:
*path to firefox*\firefox -ProfileManager

The '-ProfileManager' is necessary because every simultaneous Firefox process needs its own profile, so, this will display the profile list to create/delete/select a firefox profile.

Note that there is no assigned value to 'MOZ_NO_REMOTE', this deletes the variable from the environment.

But nobody I know likes the ugly black command line window to be opened while firefox is running. There is an option, but it is more complicated:

You can use Windows Scripting to set the environment value before running 'firefox -ProfileManager' in a simple Javascript file:

var shell = WScript.CreateObject("WScript.Shell");
var env = shell.Environment("User");
env("MOZ_NO_REMOTE") = 1;
shell.Popup('Enabling MOZ_NO_REMOTE');
shell.Exec('C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe -ProfileManager');


And save this as a file 'ON.js'. To use this script, just doubleclick on the file.

From that point on, every time you double click on 'firefox.exe' or any of the shortcuts to it you will open a new Firefox process. If you want to open more windows from a particular Firefox process, do Control-N or the equivalent, all the windows and tabs opened from a Firefox window will run within the same process.

If any other application wants to open a firefox, it will be another process, but it will fail. It will fail because firefox tries to open the last profile used, but since the last process is still using it, the profile is locked. But remember, you may still open as many windows and tabs from within every process.

To allow other applications to open firefox windows, you have to delete the MOZ_NO_REMOTE variable:

var shell = WScript.CreateObject("WScript.Shell");
var env = shell.Environment("User");
env("MOZ_NO_REMOTE") = '';
shell.Popup('MOZ_NO_REMOTE cleared');
shell.Exec('C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe -ProfileManager');

That would be 'OFF.js'

It is necessary to open a new profile because the firefox window that other applications may want to open will try to use the last profile, that is locked by the last firefox process, but even if you close this final Firefox process, from then on the default will work without trouble.

This may be a little complicated to grasp the first time, so, feel free to ask questions.