Linux – How to one change a Firefox config setting from the CLI

command linefirefoxlinuxPROXY

My objective is to be able to automate changing of a config setting without having to restart the running Firefox instance. In particular I want to change the Network Proxy Type. So for example the ideal would be something along the lines of

firefox --set network.proxy.type "1"

or

firefox --network-proxy-type "1"

Currently my workaround is by means of an Extention called "QuickProxy" which allows my to toggle the proxy setting on and off with a single click on the QuickProxy Status bar button. (Obviously this workaround does not work if you need to change other settings)

This however is still an extra step – For everything else the Proxy setting is managed dynamically via a script which plugs into Network Manager (On Kubuntu Linux), which triggers depending on the allocated IP address to turn the proxy use on or off. Only Firefox can not (presently) be so managed.

I imagine there may be a way to create a "settings" Mime type which may change a config setting, so that I could do something similar to:

firefox file:///tmp/turn-proxy-on.settings

Or maybe an add-on which makes Firefox understand new CLI options to achieve this…

But any other scriptable way of changing the setting in a running Firefox instance would suffice.

P.S. Ideally I would also like to be able to query the current values of the setting, eg by means of a command like firefox --get network.proxy.setting

Best Answer

I can't find any way to reload the prefs.js file (that's where firefox stores its settings) after changing it from the command line. That's a shame 'cause that would have been the simplest way of doing it.

However, for the specific setting you want to change, you could simply set up a proxy.pac file which checks if your IP is in a particular subnet and only sets up a proxy if it is:

if (isInNet(myIpAddress(), "192.168.1.0", "255.252.0.0")) { 
     proxy = "PROXY 123.456.789.100:12345";
}
else{
     proxy = "DIRECT";
}
return proxy;

Obviously, you should use your actual proxy's URL and port. You'll also need to modify it so it runs the correct tests (IP range etc) for your setup.

Now, open the proxy setting tab, select the "Automatic proxy configuration URL" and point it to: file:////path/to/proxy.pac. Restart firefox and you should now have your proxy set automatically depending on your IP address.

See here for more details.