9

I've seen a few programs (eg Charles Web Developer Proxy) that are able to modify Firefox's proxy settings. The sequence is:

  1. Firefox is running, with the users proxy settings.
  2. User starts the external third party application, which
  3. modifies Firefox's proxy settings, and then
  4. the user exits the third party program and,
  5. Firefox resumes running with its original proxy settings.

Assuming the external application is remembering the old proxy settings and restoring them on exit how can I read and write Firefox's proxy settings? Have tried Googling through the Firefox doco but no luck yet.

Options Considered:

  • Write a new user preferences config file and start a new instance of the browser. Would work but not quite right -- Charles for example can modify the settings of an already running browser and restore them without restarting.
  • Write a plug-in. Could write a Firefox plugin that offered some kind of IPC to the outside and then handled the Firefox preference setting itself. In fact, I think this might be the only way. Disabling Charles' Firefox plug-in seems to disable its ability to modify preferences on the fly.

Possible Resources

Hissohathair
  • 759
  • 1
  • 6
  • 17

7 Answers7

3

You might want to look at how Fiddler does this (www.fiddler2.com). The C:\program files\fiddler2\fiddlerhook\ folder has a Firefox extension which shows how this can be done.

2

All of the proxy settings for Firefox, on my machine, are stored in C:\DOCUME~1\BRUCEX~1\APPLIC~1\Mozilla\Firefox\Profiles\licga1pg.default\prefs.js . The header in that file says

# Mozilla User Preferences

/* Do not edit this file.
 *
 * If you make changes to this file while the application is running,
 * the changes will be overwritten when the application exits.
 *
 * To make a manual change to preferences, you can visit the URL about:config
 * For more information, see http://www.mozilla.org/unix/customizing.html#prefs
 */

The link to customizing.html is here. So in theory you could tweak some or all of these

user_pref("network.proxy.backup.ftp", "squid.home-server");
user_pref("network.proxy.backup.ftp_port", 3128);
user_pref("network.proxy.backup.gopher", "squid.home-server");
user_pref("network.proxy.backup.gopher_port", 3128);
user_pref("network.proxy.backup.socks", "squid.home-server");
user_pref("network.proxy.backup.socks_port", 3128);
user_pref("network.proxy.backup.ssl", "squid.home-server");
user_pref("network.proxy.backup.ssl_port", 3128);
user_pref("network.proxy.ftp", "squid.home-server");
user_pref("network.proxy.ftp_port", 3128);
user_pref("network.proxy.gopher", "squid.home-server");
user_pref("network.proxy.gopher_port", 3128);
user_pref("network.proxy.http", "squid.home-server");
user_pref("network.proxy.http_port", 3128);
user_pref("network.proxy.no_proxies_on", "localhost, 127.0.0.1, *.my-domain");
user_pref("network.proxy.share_proxy_settings", true);
user_pref("network.proxy.socks", "squid.home-server");
user_pref("network.proxy.socks_port", 3128);
user_pref("network.proxy.ssl", "squid.home-server");
user_pref("network.proxy.ssl_port", 3128);
user_pref("network.proxy.type", 1);

though there is the issue then of getting Firefox to re-read them.

bugmagnet
  • 7,233
  • 7
  • 57
  • 121
2

From what I could see from the documentation, Charles has a matching Firefox extension which it installs/uses. That may be how it can reload the proxy information on the fly.

Proxy information is stored in your profile's prefs.js, but that can't be reloaded on the fly. Firefox reads from it on startup and writes to it when it shuts down, and does not load from it in between. Also, if Firefox is running when you edit prefs.js, your changes will be overwritten.

I thought you might be able to do something with a PAC file, but after digging around a bit, I've found that it doesn't seem to be reloaded on the fly either. You'd have to restart to reload any modifications to the settings.

Athena
  • 2,970
  • 1
  • 17
  • 17
  • I am guessing that (Like another commenter eluded to with Fiddler doing similiar) these plugins are sitting between the browser and the network and rerouting / rewriting traffic. – user66001 Nov 28 '12 at 19:19
1

If you check out some of the links in the answers to my earlier question you may find code you can use to tweak the proxy settings as you required.

Community
  • 1
  • 1
bugmagnet
  • 7,233
  • 7
  • 57
  • 121
  • Thanks boost but no joy. There are poiters to code which I could use if running inside Firefox, but can't find a way if running *outside* Firefox. – Hissohathair Jan 01 '09 at 19:28
1

There is an ActiveX connection to Firefox via ActiveX Control for Hosting Netscape Plug-ins in IE but I have my doubts whether that's going to be of any help. Still, it's worth a look.

bugmagnet
  • 7,233
  • 7
  • 57
  • 121
0

I tried downloading the selenium rc 1.0.3 and used *chrome /usr/lib/firefox-3.0.10/firefox-bin followed by the URL of the AUT.It worked.Supposedly they have removed the *custom mode of running from 1.0.3(my guess) , because on , unzipping the selenium-server.jar file, I could not find any custom.class file as opposed to earlier versions where there was present a custom.class file in the selenium-server.jar file.

0

Even I was facing the issue of connection settings done to use manual proxy was not getting reflected when i was launching firefox browser from thir party application (I am working on selenium)

I tired adding users.js file in C:\Program Files\Mozilla Firefox\defaults\profile

with the changes as suggested above (adding user_pref) statements, but somehow still my firefox browser was not picking up the changes mentioned. Same thing even on my prefs.js on same location (Actually my prefs.js is empty !!)

But got some other way of doing it... in C:\Program Files\Mozilla Firefox\greprefs\all.js , do the same changes suggested above pref("network.proxy.type", 0); to 1 pref("network.proxy.http", ""); to localhost pref("network.proxy.http_port", 0); to 4444

and things started working.. But am not sure if this is the right way of doing it, since we are changing a file in installation directory.. BTW is it a bug with firefox ??

Appreciate your comments

  • all.js stores the "master" (if you will) settings. If a setting is in here, prefs.js in the user's profile folder will get the setting you wish to change from default added to it. I don't think there is any particular harm in altering all.js, just that this setting will affect how all profiles on that machine (apart from those who have explicit settings to override the defaults in all.js) make firefox operate. If your prefs.js is empty, could only guess it couldn't be written to when created / now, would first check permissions as I have never encountered a profile that has this file empty. – user66001 Nov 28 '12 at 19:22