Configuring Firefox to use a proxy from the command line

37,649

Solution 1

Firefox just can't do the standard thing and use environment variables (though to be honest this is partly justified as the standard thing doesn't allow for proxy autoconfiguration files). The preferences for static proxies are

user_pref("network.proxy.http", "wwwproxy.example.com");
user_pref("network.proxy.http_port", 3128);
user_pref("network.proxy.type", 1);

There's a Firefox extension to use $http_proxy and similar environment variables: Environment Proxy.

Recent versions of Firefox supposedly use the usual environment variables by default, or if the proxy type preference is explicitly set to 5 (“Use system proxy settings”), but it doesn't work for me with the version in Ubuntu 10.04.

user_pref("network.proxy.type", 5);

Solution 2

You say 'proxy', but your examples indicate you probably mean 'HTTP proxy' specifically. However, if you also have access to a SOCKS proxy, which does not forbid HTTP traffic, you could use the tsocks tool:

tsocks firefox

once you have configured /etc/tsocks.conf suitably.

Solution 3

According to a listing of commandline options there is no explizit option for a proxy. As you found out also neither http_proxy nor something alike works. I would suggest to first create a profile:

firefox -CreateProfile foo

Next you can use sed or whatever tool you like to write user_pref("network.proxy.http", "YOUR_PROXY"); user_pref("network.proxy.http_port", PORT); to prefs.js. Now Firefox should work fine with those proxies.

Share:
37,649

Related videos on Youtube

jstarek
Author by

jstarek

Work Innovation Engineer in a public-sector software company Previously: Scientific data management in a large petascale scientific computing facility Hobby Restoring Germany's oldest radio telescope, the Stockert 25 meter dish Learning radio astronomy and high-frequency electronics Design, construction and operation of the observatory's Linux network and scientific workstations Dabbling in Astrophotography

Updated on September 17, 2022

Comments

  • jstarek
    jstarek over 1 year

    I'm looking for a way to tell Firefox to use a proxy in Ubuntu Ludid (10.04.1 LTS).

    I'm installing Ubuntu semi-automatically on several identical machines. For this, I use a script that, amongst other things, sets system-wide proxy settings:

    echo "export http_proxy=http://myproxy:3128/" > /etc/profile.d/proxy.sh
    echo "export HTTP_PROXY=http://myproxy:3128/" >> /etc/profile.d/proxy.sh
    chmod a+x /etc/profile.d/proxy.sh
    

    I can confirm that the variables are set correctly when checking in a shell. Most programs respect this setting and use my proxy. Firefox, however, does not. When I open its network connection settings dialog, however, it is pre-set to "use system settings" for the proxy.

    What does Firefox expect here? A differently-named variable? Can I set something in FF's prefs.js?

  • jstarek
    jstarek over 13 years
    Thanks for your answers. After Gilles' hint that FF just doesn't use environment variables, I went to the Firefox's bugtracker and found this entry: bugzilla.mozilla.org/show_bug.cgi?id=224886 So the problem is known upstream. Since 2003.
  • jstarek
    jstarek over 13 years
    Thanks for the hint. Yes, I should have specified that better: There's a caching proxy for http (squid) I need to use.
  • Ubuntuser
    Ubuntuser over 5 years
    can this option be put in /etc/skel so that all future users get it?
  • h3.
    h3. over 5 years
    @Ubuntuser I don't think so. Firefox options live in a subdirectory whose name depends on which profile you're using.