Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a GM_info.userAgentData like API to get browser and OS info reliably #1728

Closed
chipzhang opened this issue Mar 3, 2023 · 5 comments
Closed

Comments

@chipzhang
Copy link

navigator.userAgent is not reliable since it may be changed by another browser extension.
It seems there is no reliable way to get browser and OS info via TM API.

ViolentMonkey has such an API:
https://violentmonkey.github.io/api/gm/#gm_info

@derjanb derjanb added this to the 4.19 milestone Mar 3, 2023
@derjanb derjanb changed the title Provide a GM_info.platform like API to get browser and OS info reliably Provide a GM_info.userAgent like API to get browser and OS info reliably Mar 3, 2023
@derjanb
Copy link
Member

derjanb commented Mar 6, 2023

Should be fixed at 4.19.6178 (crx|xpi)

I decided to go with userAgent because that's what it is.

export type UserAgentInfo = {
    platform: {
        arch: string, // 'arm' | 'x86-32' | 'x86-64' ...,
        os: string // 'android' | 'linux' | 'mac' | 'win' ...
    },
    browser: {
        name: string, // 'chrome' | 'firefox' ...
        version: string,
        vendor: string
    }
};

Chrome/Edge users, please download the crx file linked above and drag and drop it to the extensions page chrome://extensions.
Firefox users please install the BETA version or check for BETA version updates at about:addons

For a quick fix please export your settings and scripts as zip or (JSON) file at the "Utilities" tab and import it back at the fixed BETA version.

@derjanb derjanb changed the title Provide a GM_info.userAgent like API to get browser and OS info reliably Provide a GM_info.userAgentData like API to get browser and OS info reliably Mar 7, 2023
@derjanb
Copy link
Member

derjanb commented Mar 9, 2023

userAgentData is available for testing at 4.19.6179 (crx|xpi)

@chipzhang
Copy link
Author

chipzhang commented Mar 23, 2023

@derjanb

ViolentMonkey first introduces such browser checking API (as well as OS and arch checking).
As per its doc, its API reads:

  • GM_info.platform.arch: One of "arm", "mips", "mips64", "x86-32", "x86-64"
  • GM_info.platform.browserName: "chrome", "firefox" or whatever was returned by the API.
  • GM_info.platform.browserVersion
  • GM_info.platform.os: One of "android", "cros", "linux", "mac", "openbsd", "win".

Are you considering keeping the same GM_info API as ViolentMonkey, thus maximizing the compatibility of user scripts?

@7nik
Copy link

7nik commented Mar 23, 2023

It was proposed in the discussion to use the userAgentData format.

@jb222
Copy link

jb222 commented May 5, 2023

Could someone explain what has changed, with examples, please?

@derjanb derjanb closed this as completed May 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants