Firefox Proxy: bash for prefs.js

A script using variables at the end of the story, and shortly here:

#!/bin/bash

sed -En -i'.backup' '/user_pref\("network\.proxy\.(socks|socks_port|type)"/!p
$ a\
user_pref("network.proxy.socks", "127.0.0.1");\
user_pref("network.proxy.socks_port", 9050);\
user_pref("network.proxy.type", 1);
' /home/username/.mozilla/firefox/*.default-release/prefs.js

A task has arisen: how to change proxy settings in Firefox relatively quickly?

And a couple of ideas came up:
[👍] –> install a local proxy server and use it for a gateway
[🔥] –> forced change of proxy in prefs.js file

After weighing the pros and cons, of course, I chose the second option 🤦‍♂️

Here is an example of a “prefs.js” file containing profile parameters in Firefox.
The arrows point to the parameters that are responsible for the proxy settings.

// Mozilla User Preferences
...
user_pref("network.proxy.share_proxy_settings", true);
user_pref("network.proxy.socks", "111.222.333.444"); <------|
user_pref("network.proxy.socks_port", 5678); <--------------|
user_pref("network.proxy.socks_remote_dns", true); |
user_pref("network.proxy.type", 0); <-----------------------|
...

✅ Using the script at the beginning of the article, we can change these parameters to this state.

The changed parameters will appear at the end of the file, and the -i’.backup’ key will create a backup of the modified file.

// Mozilla User Preferences
.....
user_pref("network.proxy.socks", "127.0.0.1"); <-----|
user_pref("network.proxy.socks_port", 9050); <-------|
user_pref("network.proxy.type", 1); <----------------|

🔥 Bonus:

You can also use variables that will pass the necessary values

PROXY_IP="127.0.0.1"
PROXY_PORT=9050
PROXY_TYPE=1

sed -En -i'.backup' '/user_pref\("network\.proxy\.(socks|socks_port|type)"/!p
$ a\
user_pref("network.proxy.socks", '\"$PROXY_IP'\");\
user_pref("network.proxy.socks_port", '$PROXY_PORT');\
user_pref("network.proxy.type", '$PROXY_TYPE');
' /home/username/.mozilla/firefox/*.default-release/prefs.js

Please share useful cases and resources for you on using proxies or browsers.
It will be interesting to learn what’s new! Good luck with your goals! 🎉

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store