Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically create Firefox profiles

Question:

Is there a simple programmatic way to create new Firefox profiles?

nsIToolkitProfileService looks like it might do the trick but the docs say:

Starting in Gecko 18 (Firefox 18.0 / Thunderbird 18.0 / SeaMonkey 2.15 / Firefox OS 1.0.1), you should no longer use either this service or nsIToolkitProfile

Why:

I am interested to do this because I think it could be used to get independent executables of Firefox running pretty easily (e.g., so one can have a wholly separate icon in the task bar for each app) without the need for the now defunct Prism/Chromeless/WebRunner projects.

My approach would be to create a Firefox add-on which allowed the user to specify a web app URL and then would auto-create for them a namespaced profile like "Executable1", "Executable2", etc. for the app as well as a batch file which would invoke the command line "-no-remote" argument against that profile and app (since -no-remote seems to require a profile to create a new instance (the "-new-instance" argument I have seen mentioned in a bug does not seem to work for me).

like image 805
Brett Zamir Avatar asked Sep 10 '13 05:09

Brett Zamir


People also ask

How do I create a Firefox profile from the command line?

Firefox can be started on the command line with a path to a profile directory: firefox --profile path/to/directory . If the directory does not exist it will be created. A profile created like this will not be picked up by the Profile Manager.

How do I transfer my Firefox profile to another account?

The file location is "%APPDATA%\Mozilla\Firefox\Profiles". Simply copy that, throw it on a flash drive, and then move it to the same location on the new machine.

What is the Run command for opening Firefox profile manager?

To start the Profile Manager, type firefox.exe -P into a command window.


2 Answers

My guess is that people either wanted to avoid main-thread I/O. Or there were talks to remove the profile manager from the app to make startup faster and simplify startup code in general, so that might be the reason. Seems like wiki user "victorporof" did make this edit, so you probably should ping him for an explanation (IIRC, he's got an @mozilla.com address you could easily google ;)

Anyway, a new profile isn't much more than an empty directory. The application will actually copy/create missing files as soon as it starts. So your add-on could just:

  • Create an empty directory in the desired location.
  • Open an instance: -no-remote -profile $dir
  • Add icons or whatever.
  • Be done with it.
  • Optionally mess with profiles.ini, so that the new profile gets listed in the regular profile manager.

I regularly do stuff like this from command line, e.g.

mkdir -p central.profile && path/to/firefox -no-remote -profile $PWD/central.profile

Or just continue using nsITOolkitProfileService until it is actually removed. (That's what I would probably do). FWIW, there is even newish code still using it, like the (remote) debugger.

Also, might worth having a look at the standalone profile manager they coded up.

like image 87
nmaier Avatar answered Oct 07 '22 01:10

nmaier


So according to Neil from ask.m.o he said that the message saying not to use this service was auto put there when they made OS.File. It added that message falsely to this page. The service is available but OS.File is the prefered way. So I created some functions to do it with OS.File

LINK TO TOPIC: ask.m.o: OS.File instead of nsiToolkitProfileService?

Here it is: https://gist.github.com/yajd/9791029

It's still a work in progress needs much more fine tuning which I did in my addon Profilist, I'll release that soon and then post it here.

like image 22
Noitidart Avatar answered Oct 07 '22 00:10

Noitidart