naver / egjs-agent

Extracts browser and operating system information from the user agent string or user agent object(userAgentData).
https://naver.github.io/egjs-agent/
MIT License
110 stars 18 forks source link

Support Client Hints #33

Closed daybrush closed 4 years ago

daybrush commented 4 years ago

Prepare for Client Hints!

Chrome is currently planning to freeze user agents to improve user privacy.

Not only Chrome, but other browsers will come someday.

It is still an experimental feature until Chrome(Chromium) 86.

If you want to test, enable the flag below.

chrome://flags/#enable-experimental-web-platform-features

chrome://flags/#freeze-user-agent

In Chrome (Chrome 87, Mac, Freeze User-Agent)

Possible (You can know exactly)

import getAgent from "@egjs/agent";

const agent = getAgent();

// Check iOS
agent.os.name === "ios"
agent.os.majorVersion === 9
// Check Android
agent.os.name === "android"
agent.os.majorVersion === 4
parseFloat(agent.os.version) <= 4.4
// Check browser name
agent.browser.name === "safari"
// Check webkit
agent.browser.webkit
// Check chromium
agent.browser.chromium

Not Possible (If synchronous)

import getAgent from "@egjs/agent";
const agent = getAgent();

// If the full version is 10.5, it is displayed as 10.
agent.browser.version
// "unknown"
agent.os.name
// -1
agent.os.majorVersion

Possible (If asynchronous)

// Use Promise getAccurateAgent().then(agent => { // Check OS, OS version agent.os.name agent.os.version

// Check Browser full verion
agent.browser.version

});

// Use Callback getAccurateAgent(agent => {});



### If you dare to use synchrous, you have to choose.
* You cannot get the OS name and version other than iOS, Android.
* You can only get the major version of the browser. However, unless there is a serious bug, you will mainly check the major version.
* Instead, infer to browser, Webkit, or Chromium.