Agentv2.1.6

Extracts browser and operating system information from the user agent string.
#user-agent-parser #browser-detection

Getting Started

Browser support

IE 7+, latest of Chrome/FF/Safari, iOS 7+ and Android 2.3+ (except 3.x)

Quick steps to use:

Load files or import library

ES5

<script src="//naver.github.io/egjs-agent/release/latest/dist/agent.min.js"></script>

ES6+
import Agent from "@egjs/agent";

Use

// eg.Agent will use browser's navigator.userAgent 
var agentInfo = eg.agent();

// or you can use own user-agent string
agentInfo = eg.agent(ua);

console.log(agentInfo);
/*
    {
        browser: {
            name: "",
            version: ""
            webview: true or false
        },
        os: {
            name: "",
            version: ""
        }
    }
*/

Demos

Target User Agent

(Copy and paste the user agent string to parse)

Result

OS

name:
version:

Browser

name:
version:
webview:

isMobile

var uaInput = document.querySelector(".useragent-input");
uaInput.addEventListener("input", function() {
    var agentInfo = eg.agent(uaInput.value);
    osName.innerHTML = agentInfo.os.name;
    osVersion.innerHTML = agentInfo.os.version;
    browserName.innerHTML = agentInfo.browser.name;
    browserVersion.innerHTML = agentInfo.browser.version;
    browserWebview.innerHTML = agentInfo.browser.webview;
    isMobile.innerHTML = agentInfo.isMobile;
})