17

Is it possible to create Firefox profiles via the command line? I need to programatically launch Firefox with different proxy settings. From my understanding, I can do this via creating a profile. However, I don't want to create these profiles manually.

fixer1234
  • 28,064

2 Answers2

18

You sure can!

example:

firefox -CreateProfile john

check out the rest of Firefox's command line arguments.

Once your profile is created and configured you can launch the profile by doing the following:

firefox -P john
heavyd
  • 65,321
0

The simple answer from 2010 (firefox -CreateProfile profile_name) doesn't work anymore in recent Firefox versions.

Credit to @Waylander in a comment to the old answer, he notes that you have to add some more arguments:

firefox -CreateProfile profile_name --headless --screenshot /dev/null

Indeed that works, also in Firefox Nightly (currently version 134.0a1).

Warning though - this will create a profile folder named random.profile_name where random are 8 random characters. I'm not aware of a way to get rid of this randomness, other than below.

So, if you'd like to create a profile at some exact path, you can:

  1. just make a new folder in your Firefox profiles root folder, or anywhere else:

    mkdir -p ~/.mozilla/firefox/profile_name
    
  2. Add correct entry to ~/.mozilla/firefox/profiles.ini in any way you'd like (script or not).

    [Profile#]
    Name=profile_name
    IsRelative=1
    Path=profile_name
    

    Important: # has to be a number which is next in sequence considering other profiles defined in profiles.ini. If you make a mistake, your new profile will not be detected and so it won't even show up in the Profile Manager (firefox --ProfileManager).

    If you set IsRelative to 0, then set Path to full absolute path to the profile folder.

  3. Create a user.js in your profile folder (e.g. ~/.mozilla/firefox/profile_name/user.js), which enables you to configure your Firefox profile before the 1st launch.

    A lot can be achieved with user.js, few examples below:

    If you're looking how to set some specific config value, you have to first know its key. If searching on the Internet doesn't work out, you can always run Firefox in your default profile, and study the values in about:config. Then put the same key you found into user.js with the value you'd like. For example, to set HTTPS proxy port to 443:

    user_pref("network.proxy.ssl_port", 443);
    
  4. Launch your configured Firefox now with firefox -P profile_name.

mbdevpl
  • 491