Nutella with Pepperoni and Mushrooms

    browser-dtector
    TypeScript icon, indicating that this package has built-in type declarations

    3.2.0 • Public • Published

    browser-dtector Tests

    A Javascript library to detect browser, version and platform

    Getting Started

    Installation

    Install via Package managers such as npm or yarn

    npm install browser-dtector --save
    # or
    yarn add browser-dtector

    or use cdn

    Minified:

    //cdn.jsdelivr.net/npm/browser-dtector@latest/browser-dtector.esm.min.js

    Pretty Printed:

    //cdn.jsdelivr.net/npm/browser-dtector@latest/browser-dtector.esm.js

    Usage

    This library is compiled to UMD format, you should be able to use it in both Node.js and browser.

    import BrowserDetector from 'browser-dtector';
    
    const browser = new BrowserDetector(window.navigator.userAgent);
    browser.parseUserAgent();

    Usage in Node.js:

    Note: while using in nodejs, it is mandatory to input useragent.

    const http = require('http');
    const BrowserDetector = require('browser-dtector');
    
    const browser = new BrowserDetector();
    
    http
      .createServer((req, res) => {
        // get user-agent header
        const ua = browser.parseUserAgent(req.headers['user-agent']);
        // write the result as response
        res.end(JSON.stringify(ua, null, 4));
      })
      .listen(8080, '127.0.0.1');
    
    console.log('Server running at http://127.0.0.1:8080/');

    Usage in HTML:

    <!DOCTYPE html>
    <html lang="en">
      <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <meta http-equiv="X-UA-Compatible" content="ie=edge" />
        <title>BrowserDetector</title>
      </head>
    
      <body>
        Hello World!
        <script type="module">
          import BrowserDetector from 'https://cdn.jsdelivr.net/npm/browser-dtector/browser-dtector.esm.js';
    
          const detector = new BrowserDetector(window.navigator.userAgent);
          console.log(detector.parseUserAgent());
        </script>
      </body>
    </html>

    Supported Browsers

    • Google Chrome
    • Mozilla Firefox
    • Microsoft Edge
    • Safari
    • Brave
    • Microsoft Internet Explorer
    • Opera
    • Samsung Browser
    • Electron

    Supported Platforms

    • Macintosh
    • Microsoft Windows
    • Linux
    • Windows Phone
    • Android
    • Android Tablet
    • IPad
    • IPhone
    • Chrome OS
    • Microsoft Xbox

    Demo

    API

    Sample

    import BrowserDetector from 'browser-dtector';
    
    const browser = new BrowserDetector(window.navigator.userAgent);
    browser.parseUserAgent();
    • parseUserAgent() [object]: Returns parsed useragent info

      {
        "name": "Google Chrome",
        "platform": "Macintosh",
        "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) ...",
        "version": "71.0.3578.98",
        "shortVersion": "71",
        "isAndroid": false,
        "isTablet": false,
        "isMobile": false,
        "isDesktop": true,
        "isWebkit": true,
        "isIE": false
      }
    • getBrowserInfo() [object]: Returns a minimal and necessary browser info.

      {
        "name": "Google Chrome",
        "platform": "Macintosh",
        "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) ...",
        "version": "71.0.3578.98",
        "shortVersion": "71"
      }
    • userAgent [string | null]: Useragent for current instance

    Miscellaneous:

    • BrowserDetector.VERSION [string]: Current version of the library.

    Install

    npm i browser-dtector

    DownloadsWeekly Downloads

    373

    Version

    3.2.0

    License

    MIT

    Unpacked Size

    97.1 kB

    Total Files

    17

    Last publish

    Collaborators

    • sibiraj-s