I want os name, os version, browser name, browser version and device from the user agent. How can I use user agent parser js in my application in angular 4. I tried ng2-device-detector@1.0.0 but it doent return me the os version and device. Please help me
            Asked
            
        
        
            Active
            
        
            Viewed 4,701 times
        
    2 Answers
5
            
            
        To add it to package.json:
npm install ua-parser-js
To use it in your components or services you need an import for it to work:
import { UAParser } from 'ua-parser-js'; 
let parser = new UAParser();
console.log(parser.getResult());
I found the missing import in this other SO answer. Then you can use the documentation to get whatever information you're looking for.
        Sofía
        
- 784
 - 10
 - 24
 
1
            
            
        The UAParser.js documentation is your best ally.
You can get OS name and version, browser name and other information using UAParser.js like that:
var parser = new UAParser();
// by default it takes ua string from current browser's window.navigator.userAgent
console.log(parser.getResult());
var result = parser.getResult();
console.log(result.browser);        // {name: "Chromium", version: "15.0.874.106"}
console.log(result.device);         // {model: undefined, type: undefined, vendor: undefined}
console.log(result.os);             // {name: "Ubuntu", version: "11.10"}
console.log(result.os.version);     // "11.10"
console.log(result.engine.name);    // "WebKit"
console.log(result.cpu.architecture);   // "amd64"
        JoH
        
- 514
 - 1
 - 6
 - 16