Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

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.

share|improve this answer
    
When is this pac file read? Can one dynamically edit the file? –  Johan Jan 9 at 13:15
    
@Johan I don't think so, it is read when firefox starts. However, it will be run every time you attempt to connect to a server so if your IP has changed, the proxy will be different. That's the idea anyway. The file is just a javascript function run by firefox before connecting to any webpage. So, you don't need to edit the file, just set it up as I have shown you so that it returns a different proxy based on your IP. –  terdon Jan 9 at 13:17
    
I found hints around the web suggesting that changing prefs.js and restarting Firefox will cause the changes to be lost as Firefox may flush changed settings to prefs.js. –  Johan Jan 9 at 15:25
    
@Johan I am not recommending you touch prefs.js at all. That was just the first thing I tried but it did not seem to work. The .pac file has nothing to do with prefs.js. –  terdon Jan 9 at 15:30
    
I am still looking for a way to change the Proxy configuration (maybe point it at a new PAC file) while Firefox is running, via a script or similar external command. I think your solution would solve 90% of similar problems, and mine too, but it doesn't answer my question. I knew of the existence of PAC files but dismissed them because I don't think they are dynamic controllable except via the GUI. –  Johan Jan 10 at 8:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.