Help with browser.proxy.settings.get()

Hi All,

So I want to store the browsers current proxy settings when add on is used the first time so user can switch easily back to those settings using my proxy switcher add on but I can’t find documentation about or examples of how to call browser.proxy.settings.get() successfully. Can anyone point me in the right direction? I keep getting this error:

Error: Incorrect argument types for types.Setting.get.

Unless I call it like so:

browser.proxy.settings.get({}), in which case i just get back an empty json object.

Any help would be very appreciated.

Thank you in advance.

Why do you want to storethe current settings? If you want to restore the previous settings, you just unset your settings.

Good question. So, If I’m allowing the user to add multiple potential proxy servers and to switch between them, if they use server 1, then server 2, then want to revert to their original settings, I don’t have those anymore. Previous settings would be server 1. Or am I wrong about this…?

[edit] I just tested unsetting the proxy server user added to my addon and it sets back to Use System Proxy, no matter what it was before. So, even if user only changes settings once, unsetting those changes won’t cause proxy settings to revert to what was before.

[edit 2] According to the “set” documentation found here, if you call set with any of the fields not set, it reverts to “default” settings, not previous settings and I can’t find a way to restore previous settings even :slight_smile: Ok I’ll stop editing now and hang tight in hopes that someone can point me to the correct documentation so I can sort this! Thanks again for any guidance.

And the question remains: how do I use or where can I find documentation on using browser.proxy.settings.get().

Right, so proxy.settings is a BrowserSetting, for which get is documented here:

I’m not sure if you can get the default values, however I’d assume you could at least read values that you’ve set yourself. However if you’ve set the values yourself you may also be able to keep track of them in something like extension storage or similar, so you can provide a more sophisticated experience than just being able to revert to the (one) previous value.

Yeah, that documentation doesn’t help unfortunately. And yes, I am saving what user sets proxy settings to in my addon and am able to reuse those, and I know what the defaults are because they are well documented. I am asking very specifically for detailed information on how to use browser.proxy.settings.get() because I want to get the browsers proxy setting when my addon is first used (these may or may not be the “defaults”) so I can set them back if necessary. I am not looking for help with application logic or ways around this. If you can point me to documentation on how to use this specific function, what parameters need to be passed in to get back what I am asking for, definitely let me know that.

Okay, so for this specific case unsetting your proxy settings should go back to the settings the user had previously, and not the default values of the browser. As such you should not need to read out the current values when your extension is initially activated.

Thanks for all of your replies. One last question: How would I “unset” the settings I’ve set? I tried to pass into browser.proxy.settings.set() an empty json object but that just set everything to the default settings, not the settings I had set prior to adding my addon… It overwrote all of my urls that I didn’t want proxied, for example.

Hey @freaktechnik. You actually pointed me in the right direction, I just misread the documentation completely. The answer was in your link to BrowserSetting.get().

Final answer from

var getting = browser.proxy.settings.get({});

getting.then((got) => {
  console.log(`Control: ${got.levelOfControl}`);

An example of what got.value looks like:

autoConfigUrl: ""
autoLogin: true
ftp: ""
http: ""
httpProxyAll: false
passthrough: ","
proxyDNS: true
proxyType: "autoDetect"
respectBeConservative: true
socks: ""
socksVersion: 5
ssl: ""
<prototype>: Object { … }

Thank you so much for taking the time to respond to my query!