UAPraser - User Agent Parser

UAParser is an open source library for parsing the browser user agent. It’s a lightweight and easy to use library with a minified file size of ~11KB; as the library name says, the primary purpose of UAParser is to parse the user agent and get the relevant information about the browser, engine, operating system, device and CPU architecture.

Please find the library located at Github: UAParser.js

Below are the results of the parsed user agent information. The below information is based on readme.md of ua-parser library.

  1. {  
  2.     ua: "",  
  3.     browser:  
  4.     {  
  5.         name: "",  
  6.         version: ""  
  7.     },  
  8.     engine:  
  9.     {  
  10.         name: "",  
  11.         version: ""  
  12.     },  
  13.     os:  
  14.     {  
  15.         name: "",  
  16.         version: ""  
  17.     },  
  18.     device:  
  19.     {  
  20.         model: "",  
  21.         type: "",  
  22.         vendor: ""  
  23.     },  
  24.     cpu:  
  25.     {  
  26.         architecture: ""  
  27.     }  
  28. }  
Download and include the script in your HTML webpage and start using it to parse the user agent.
  1. <script type="text/javascript" src="ua-parser.min.js">  
  2. </script>  
Below is the code snippet for creating a UAParser. By default, the parser makes use of window.navigator.userAgent as the user agent to get the parsed results. However, there is an option to explicitly set the user agent and parse the same.
  1. var parser = new UAParser();  
  2. var browserInfo = parser.getResult();  
Below is the variation of the usage of UAParser
  1. console.log(parser.getOS().name);  
  2. console.log(parser.getOS().version);  
  3. console.log(parser.getEngine());  
  4. console.log(parser.getBrowser().name);  
  5. console.log(parser.getBrowser().version);  
Here’s the demo code sample illustrating the usage of UAParser. The below code sample is based on ua-parser library readme.md.
  1. <!doctype html>  
  2. <html>  
  3. <head>  
  4.   <script type="text/javascript" src="ua-parser.min.js">  
  5.    </script>  
  6.         <script type="text/javascript">  
  7.         var parser = new UAParser();  
  8.         var result = parser.getResult();  
  9.         console.log(result.browser);  
  10.         console.log(result.device);  
  11.         console.log(result.os.name);  
  12.         console.log(result.os.version);  
  13.         console.log(result.engine.name);  
  14.         console.log(result.cpu.architecture);  
  15.    </script>  
  16. </head>  
  17. <body>  
  18.     <h1>Please right click and select the Inspect Element -> Console option to view the user agent results</h1>  
  19. </body>  
  20. </html>  
output

 

X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now