All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.src.browser-utils.js Maven / Gradle / Ivy

There is a newer version: 24.5.3
Show newest version
/**
 * @license
 * Copyright (c) 2021 - 2024 Vaadin Ltd.
 * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
 */

const testUserAgent = (regexp) => regexp.test(navigator.userAgent);

const testPlatform = (regexp) => regexp.test(navigator.platform);

const testVendor = (regexp) => regexp.test(navigator.vendor);

export const isAndroid = testUserAgent(/Android/u);

export const isChrome = testUserAgent(/Chrome/u) && testVendor(/Google Inc/u);

export const isFirefox = testUserAgent(/Firefox/u);

// IPadOS 13 lies and says it's a Mac, but we can distinguish by detecting touch support.
export const isIPad = testPlatform(/^iPad/u) || (testPlatform(/^Mac/u) && navigator.maxTouchPoints > 1);

export const isIPhone = testPlatform(/^iPhone/u);

export const isIOS = isIPhone || isIPad;

export const isSafari = testUserAgent(/^((?!chrome|android).)*safari/iu);

export const isTouch = (() => {
  try {
    document.createEvent('TouchEvent');
    return true;
  } catch (_) {
    return false;
  }
})();




© 2015 - 2024 Weber Informatics LLC | Privacy Policy