ray-lothian / UserAgent-Switcher

A User-Agent spoofer browser extension that is highly configurable
https://webextension.org/listing/useragent-switcher.html
Mozilla Public License 2.0
923 stars 143 forks source link

How to automatically return latest version of Chrome? #76

Closed Mr-Personality closed 3 years ago

Mr-Personality commented 4 years ago

I was asking about this on this thread but the thread was closed. (Sorry to have to make a new thread.)

I just want it to automatically return the latest version of Chrome / Windows 10. You suggested using ${}" placeholders, as mentioned in the FAQ, but that is above my head. I don't understand what to do. Please could you tell me how to do it?

DMW007 commented 4 years ago

I'd like to have the same functionality, but for Mozilla Firefox instead of Chrome. The problem with the ${} placeholders is that they replace vars just for the navigator object. The navigator object doesn't have a dedicated property for the Browser version. The only thing we get is the original navigator.userAgent. It would be possible to extract the real browser version from the agent like this on Firefox:

navigator.userAgent.match(/Firefox\/([0-9]+)\./)[1]
"75"

So we need to do something like

Mozilla/5.0 (X11; Linux x86_64; rv:75.0) Gecko/20100101 Firefox/${navigator.userAgent.match(/Firefox\/([0-9]+)\./)[1]}

which cannot work because everything between ${ and } is used as var name in the navigator object.

Since you're using https://github.com/faisalman/ua-parser-js the simplest way to solve this would be letting the library parse the UA string and set browser.version to the navigator object which is used in line 108 for resolving $ variables. So we simply could use something like

Mozilla/5.0 (X11; Linux x86_64; rv:${browser.version}) Gecko/20100101 Firefox/${browser.version}

and we have a custom user agent string where ${browser.version} got always replaced by the (latest) version we're currently really using. This solves the following problem: In the past I selected Firefox 74. Now this is outdated since Firefox 76 got avaliable. When I don't update the UA to the latest version from time to time, some web sites doesn't work (correctly) since they check browser versions.

This is also noticeable in terms of privacy. Browsers got automatically updated. When my browser is reported as a old version weeks after newer versions were released, it's much easier to recognize me since other users have more recent UAs.

Kristinita commented 4 years ago

Type: Addition

+1 to all @DMW007 arguments.

Also, some web-sites have scripts such as browser-update.js. If script detect old browser version, site may works incorrectly.

Thanks.

ray-lothian commented 3 years ago

We are going to support the new ${dot-separated.keys|ua-parser@custum-user-agent-string}" syntax. So this is going to work:

Mozilla/5.0 (X11; Linux x86_64; rv:${browser.version|ua-parser}) Gecko/20100101 Firefox/${browser.version|ua-parser}

Kristinita commented 3 years ago

Status: CONFIRMED :heavy_check_mark:

1. Environment

  1. Windows 10.0.18363 Pro N for Workstations 64-bit EN
  2. Firefox 80.0.1 (64-bit)
  3. User-Agent Switcher and Manager 0.4.3

2. Custom user-agent string

Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:${browser.version|ua-parser}) Gecko/20100101 Kubuntu/20.04 (Intrepid) Firefox/${browser.version|ua-parser}

3. Result

WebBrowserTools

Thanks.

curbengh commented 2 years ago

We are going to support the new ${dot-separated.keys|ua-parser@custum-user-agent-string}" syntax. So this is going to work:

Mozilla/5.0 (X11; Linux x86_64; rv:${browser.version|ua-parser}) Gecko/20100101 Firefox/${browser.version|ua-parser}

It's not supported in custom mode?

{
  "my-custom-useragent": {
    "appVersion": "5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${browser.version|ua-parser} Safari/537.36",
    "platform": "Win32",
    "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${browser.version|ua-parser} Safari/537.36"
  }
}

outputs

{
          const script = document.createElement('script');
          script.textContent = `{
            document.currentScript.dataset.injected = true;
            const o = JSON.parse('{"userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${browser.version|ua-parser} Safari/537.36","appVersion":"5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${browser.version|ua-parser} Safari/537.36","platform":"Win32"}');
...

browser console then shows Uncaught ReferenceError: browser is not defined error because that's a template string.

tomas-chrastina commented 1 year ago

Hello,

what I would like to have "simpler" placeholder(s) to use predefined configuration in Custom Mode something like: "<site>":${<platform[:version]>|<browser[:version]>

For version have an option to use value latest for auto-detection. Or just when version is not defined, use latest automatically?

Example:

{
    "site1.com":${windows:10|edge:103.0.1253.0},
    "site2.org":${android:latest|firefox:latest}
    "site3.org":${linux|chrome}
}

Form can be different, but to have an option to use it the same way as you can change it via settings.