Extracts browser and operating system information from the user agent string or user agent object(userAgentData).
#user-agent-parser #browser-detection #client-hints
The following are the supported browsers.
<script src="//naver.github.io/egjs-agent/release/latest/dist/agent.min.js"></script>
$ npm i @egjs/agent
import getAgent from "@egjs/agent";
// getAgent(eg.agent) will use browser's navigator.userAgentData or navigator.userAgent
var agentInfo = getAgent(); // or eg.agent();
// or you can use own user-agent string
agentInfo = getAgent(ua);
console.log(agentInfo);
/*
{
browser: {
name: "string",
version: "number",
majorVersion: number,
webview: true or false,
webkit: true or false,
chromium: true or false,
},
os: {
name: "string",
version: "number",
majorVersion: number,
},
isHints: ture or false,
}
*/
getAccurateAgent(eg.agent.getAccurateAgent)
instead of getAgent(eg.agent)
import { getAccurateAgent } from "@egjs/agent";
// Use Promise
// eg.agent.getAccurateAgent
getAccurateAgent().then(agent => {
// Check OS, OS version
agent.os.name
agent.os.version
// Check Browser full verion
agent.browser.version
});
// Use Callback
getAccurateAgent(agent => {});
name:
version:
majorVersion:
name:
version:
majorVersion:
webview:
webkit:
chromium:
var uaInput = document.querySelector(".useragent-input");
uaInput.addEventListener("input", function() {
var agentInfo = eg.agent();
osName.innerHTML = agentInfo.os.name;
osVersion.innerHTML = agentInfo.os.version;
osMajorVersion.innerHTML = agentInfo.os.majorVersion;
browserName.innerHTML = agentInfo.browser.name;
browserVersion.innerHTML = agentInfo.browser.version;
browserMajorVersion.innerHTML = agentInfo.browser.majorVersion;
browserWebview.innerHTML = agentInfo.browser.webview;
browserWebkit.innerHTML = agentInfo.browser.webkit;
browserChromium.innerHTML = agentInfo.browser.chromium;
isHints.innerHTML = agentInfo.isHints;
isMobile.innerHTML = agentInfo.isMobile;
})