Détail du package

@braintree/browser-detection

braintree2.4mMIT2.0.2

A small lib to detect browser compatibility for braintree products

readme

Browser Detection

A utility for detecting browser support for Braintree libs.

Example

const browserDetection = require("browser-detection");

browserDetection.isAndroid();
browserDetection.isChromeOS();
browserDetection.isChrome();
browserDetection.isDuckDuckGo();
browserDetection.isEdge();
browserDetection.isFirefox();
browserDetection.isSafari();
browserDetection.isIe();
browserDetection.isIe9();
browserDetection.isIe10();
browserDetection.isIe11();
browserDetection.isIos();
browserDetection.isIosFirefox();
browserDetection.isIosGoogleSearchApp();
browserDetection.isIosSafari();
browserDetection.isIosWebview();
browserDetection.isIosUIWebview();
browserDetection.isIosWKWebview();
browserDetection.isIpadOS();
browserDetection.isMobileFirefox();
browserDetection.isOpera();
browserDetection.isSamsungBrowser();
browserDetection.isSilk();
browserDetection.hasSoftwareKeyboard();
browserDetection.supportsPaymentRequestApi();
browserDetection.supportsPopups();

To reduce build sizes, you can require just the modules you need:

const isAndroid = require("browser-detection/is-android");
const isChromeOS = require("browser-detection/is-chrome-os");
const isChrome = require("browser-detection/is-chrome");
const isDuckDuckGo = require("browser-detection/is-duckduckgo");
const isEdge = require("browser-detection/is-edge");
const isFirefox = require("browser-detection/is-firefox");
const isSafari = require("browser-detection/is-safari");
const isIe = require("browser-detection/is-ie");
const isIe9 = require("browser-detection/is-ie9");
const isIe10 = require("browser-detection/is-ie10");
const isIe11 = require("browser-detection/is-ie11");
const isIos = require("browser-detection/is-ios");
const isIosFirefox = require("browser-detection/is-ios-firefox");
const isIosGoogleSearchApp = require("browser-detection/is-ios-google-search-app");
const isIosSafari = require("browser-detection/is-ios-safari");
const isIosWebview = require("browser-detection/is-ios-webview");
const isIosUIWebview = require("browser-detection/is-ios-uiwebview");
const isIosWKWebview = require("browser-detection/is-ios-wkwebview");
const isIpadOS = require("browser-detection/is-ipados");
const isMobileFirefox = require("browser-detection/is-mobile-firefox");
const isOpera = require("browser-detection/is-opera");
const isSamsungBrowser = require("browser-detection/is-samsung");
const isSilk = require("browser-detection/is-silk");
const hasSoftwareKeyboard = require("browser-detection/has-software-keyboard");
const suportsPaymentRequestApi = require("browser-detection/supports-payment-request-api");
const supportsPopups = require("browser-detection/supports-popups");

Testing

npm test

Notes on isIpadOs

isIpadOS is a new option for browser detection, and is also included in isIos. isIos defaults to checking for iPads to maintain consistent behavior with how it acted in the past. If checkIpadOS is set to false, then it will only check for older gen iPads and current iOS

const browserDetection = require("browser-detection");
const ua = window.navigator.userAgent;
// assume ua is from iPadOs 13 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.4 Safari/605.1.15"
browserDetection.isIos(ua);
// will return true
browserDetection.isIos(ua, false);
// will return false

Notes on Safari

is-safari is used for desktop Safari detection, if you are trying to detect an iOS version of Safari, use is-ios-safari.

changelog

Browser Detection - Release Notes

2.0.2

  • Update (sub-)dependencies
    • cross-spawn to 7.0.6
    • micromatch to 4.0.8

2.0.1

  • Updates braces to 3.0.3
  • Updates ws to 8.17.1

2.0.0

  • BREAKING CHANGES:
    • Update Node to v18
  • DevDependency Updates:
    • Prettier to v3
    • eslint-plugin-prettier to v5
    • @types/node to v20
    • Typescript to v5

1.17.2

  • Fix edge detection by also checking for "Edg/" in userAgent (authored by @petercmuc)

1.17.1

  • Migrate back to jest
  • Remove ES6 style imports/exports in /src directory

1.17.0

  • Add is-safari method for desktop Safari detection (#48)
  • Migrate tests from jest to vitest

1.16.0 (2023-05-08)

  • Remove window.safari object validation from iOS webview.
  • Update is-ios to account for user agent behavior on newer iPads
  • Add is-ipados method
  • Typoed version number so we are skipping all the way to 1.16.0

1.13.0 (2022-07-14)

  • Update mobile webview definitions to ensure modern webviews are accounted for.

1.12.1 (2021-09-28)

  • Correct is-ios-safari to return false for the Facebook browser

1.12.0 (2021-06-08)

  • Add is-duckduckgo method
  • Add is-ios-google-search-app method
  • Add is-opera method
  • Add is-silk method
  • Fix issue where is-chrome would incorrectly report true for DuckDuckGo and Silk browsers
  • Fix issue where supports-popups would incorrectly report false for DuckDuckGo

1.11.1 (2021-04-07)

  • Fix issue where is-ios-safari was returning true for iOS Firefox browsers

1.11.0 (2020-10-27)

  • Add has-software-keyboard method

1.10.1 (2020-10-19)

  • Fix issue where typescript declarations did not get published

1.10.0 (2020-07-10)

  • Add typescript types

v1.9.0 (2019-09-18)

  • Add is-firefox method

v1.8.0 (2019-08-07)

  • Add is-chrome-os method
  • Fix README typo for iOS
  • Update README code samples to use const

1.7.0 (2017-10-18)

  • Add supports-payment-request-api method

1.6.0 (2017-07-25)

  • Correct is-chrome to not return true on edge browser
  • Correct supports-popups to not return true on iOS Firefox
  • Add is-samsung-browser method
  • Add is-mobile-firefox method
  • Add is-ios-firefox method

1.5.0 (2017-07-03)

  • Add is-ie method
  • Add is-ie11 method
  • Add is-edge method

1.4.1 (2017-06-01)

  • publish to npm as scoped package @braintree/browser-detection

1.4.0 (2017-05-22)

  • Add is-ios-uiwebview method
  • Add is-ios-wkwebview method

1.3.0 (2017-04-11)

  • Add is-ios-webview method
  • Add is-ios-safari method

1.2.0 (2017-04-10)

  • Add is-ie10 method

1.1.0 (2017-04-07)

  • Add is-chrome method

1.0.0 (2017-04-05)

  • Initial public release of browser-detection