Browser Detector & UserAgent Parser – browser-dtector.js

Category: Javascript | July 5, 2020
Author: sibiraj-s
Views Total: 25 views
Official Page: Go to website
Last Update: July 5, 2020
License: MIT

Preview:

Browser Detector & UserAgent Parser – browser-dtector.js

Description:

Just another browser detection library to detect browser and platform properties for both browser and node.js.

Supported Browsers:

  • Chrome
  • Firefox
  • Internet Explorer
  • MS Edge
  • Safari
  • Opera
  • Samsung Browser
  • Brave

Supported Platforms:

  • Macintosh
  • Windows
  • Linux
  • Windows Phone
  • Android
  • Android Tablet
  • iPad
  • iPhone
  • Chrome OS
  • Xbox

How to use it:

1. Install and import the ‘browser-dtector’.

# Yarn
$ yarn add browser-dtector

# NPM
$ npm install browser-dtector --save
import BrowserDtector from 'browser-dtector';

2. Or load the ‘browser-dtector.umd.min.js’ from a CDN.

<script src="https://cdn.jsdelivr.net/npm/[email protected]/browser-dtector.umd.min.js"></script>

3. Initialize the library.

const browser = new window.BrowserDtector(window.navigator.userAgent); 
// or new BrowserDtector()

4. Parse useragent info.

browser.parseUserAgent();

=>

{
  name: "Safari"
  platform: "IPhone"
  userAgent: "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1"
  version: "13.0.3"
  shortVersion: "13"
  isAndroid: false
  isTablet: false
  isMobile: true
  isDesktop: false
  isWebkit: true
  isIE: false
}

5. Get browser info.

browser.getBrowserInfo();

=>

{
  name: "Safari"
  platform: "IPhone"
  userAgent: "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1"
  version: "13.0.3"
  shortVersion: "13"
}

6. Get browser name.

browser.getBrowserName();

=> Safari

7. Get browser version.

browser.getBrowserVersion();

=> 13.0.3

8. Get browser short version.

browser.getBrowserShortVersion();

=> 13

9. Get platform name.

browser.getPlatformName();

=> IPhone

Changelog:

v3.1.1 (07/05/2020)

  • Supports Brave browser
  • Bugfix

v3.0.2 (07/01/2020)

  • Bugfixed

You Might Be Interested In:


Leave a Reply