Monday, 22 March 2021

How to Change Firefox Proxy Settings Programmatically?

I'm launching Firefox via command line and I'd like to launch a specific Firefox Profile using a proxy. According to this answer, Firefox proxy settings are stored in pref.js in the Firefox Profile folder and it is necessary to edit this file to run FF with a proxy.

I've edited the file as follows:

user_pref("network.proxy.ftp", "1.0.0.1");
user_pref("network.proxy.ftp_port", 00000);
user_pref("network.proxy.gopher", "1.0.0.1");
user_pref("network.proxy.gopher_port", 00000);
user_pref("network.proxy.http", "1.0.0.1");
user_pref("network.proxy.http_port", 22222);
user_pref("network.proxy.no_proxies_on", "localhost, 1.0.0.1");
user_pref("network.proxy.socks", "1.0.0.1");
user_pref("network.proxy.socks_port", 00000);
user_pref("network.proxy.ssl", "1.0.0.1");
user_pref("network.proxy.ssl_port", 00000);
user_pref("network.proxy.type", 1);

Note: the IP address and port have been changed for demonstration purposes.

However, I'm encountering two problems:

1) Firefox completely ignores these settings and launches FF without any proxy at all

2) When Firefox exits the text modification is reverted/deleted

Note: When I edited the text file above, Firefox was not running. I know there's a disclaimer at the top of prefs.js:

If you make changes to this file while the application is running, the changes will be overwritten when the application exits.

But there were no live instances of Firefox running at the time I edited the above file.

Manually creating different FF Profiles (as suggested by another user) with different proxies is not an option as everything needs to be done programmatically on the fly.

Does Firefox still support linking proxy via pref.js? If not, what is a current working solution to launch Firefox via command line with a proxy using Java?

Thanks



from How to Change Firefox Proxy Settings Programmatically?

No comments:

Post a Comment