foxyproxy / firefox-extension

FoxyProxy for Firefox extension beginning with Firefox 57 (Quantum)
GNU General Public License v2.0
523 stars 115 forks source link

Proxy by patterns not working if firefox users change their userAgent to another platform #220

Closed mika-cn closed 9 months ago

mika-cn commented 9 months ago

Users that want to prevent fingerprint trackers may spoof their userAgent String to another total different type of browser (Chrome for example).

In version 8.9 of FoxyProxy, the file content/app.js use following code to detect browser type.

// content/app.js
export class App {

  static firefox = navigator.userAgent.includes('Firefox');
  static android = navigator.userAgent.includes('Android');
  ...
}

Here, navigator.userAgent may not contains 'Firefox' even the browser IS Firefox. So other code that depends on App.firefox may not work as expected.

In my test, The following code throw an error.

// content/proxy.js
  static async set(pref) {
    ...
    App.firefox ? this.setFirefox(pref, conf) : this.setChrome(pref);
    ...
  }

Here, this.setChrome(pref) get executed and throw an error about incognito staff. All defined patterns are not working, web requests were sent like there's not proxy at all.


The browser type can be known when packing the extension. So we don't need to rely on navigator.userAgent here, as for detecting the OS, maybe we could use this API.

For debugging, you can change the userAgent of Firefox by enter about:config page. And add an item called general.useragent.override, Here's one value that i copy from the web Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3690.90 Safari/537.36 .

BTW, thank you for this amazing addon :)

erosman commented 9 months ago

runtime.getBrowserInfo() is the right API to get the browser details e.g.

browser.runtime.getBrowserInfo().then(console.log);

// { name: "Firefox", vendor: "Mozilla", version: "124.0a1", buildID: "20240213210653" }

Unfortunately, the API is not supported on Chrome. I can workout a hacky way to detect but that is not 100% reliable. Let me see if there is any other option.

See also: Ability to detect browser variant / fork

PS. The repository for v8+ is https://github.com/foxyproxy/browser-extension

erosman commented 9 months ago

I have updated the browser detection for v8.10