How to use detect-browser - 10 common examples

To help you get started, we’ve selected a few detect-browser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mozilla / hubs / src / hub.js View on Github external
await store.initProfile();

  const canvas = document.querySelector(".a-canvas");
  canvas.classList.add("a-hidden");

  warmSerializeElement();

  if (!window.WebAssembly) {
    remountUI({ showWebAssemblyDialog: true });
    return;
  }

  // If we are on iOS but we don't have the mediaDevices API, then we are likely in a Firefox or Chrome WebView,
  // or a WebView preview used in apps like Twitter and Discord. So we show the dialog that tells users to open
  // the room in the real Safari.
  const detectedOS = detectOS(navigator.userAgent);
  if (detectedOS === "iOS" && !navigator.mediaDevices) {
    remountUI({ showSafariDialog: true });
    return;
  }

  const hubId = qs.get("hub_id") || document.location.pathname.substring(1).split("/")[0];
  console.log(`Hub ID: ${hubId}`);

  const subscriptions = new Subscriptions(hubId);

  if (navigator.serviceWorker) {
    try {
      navigator.serviceWorker
        .register("/hub.service.js")
        .then(() => {
          navigator.serviceWorker.ready
github mozilla / hubs / src / utils / vr-caps-detect.js View on Github external
const { detect } = require("detect-browser");

const browser = detect();

// Precision on device detection is fuzzy -- we can sometimes know if a device is definitely
// available, or definitely *not* available, and assume it may be available otherwise.
export const VR_DEVICE_AVAILABILITY = {
  yes: "yes", // Implies VR can be launched into on this device immediately, in this browser
  no: "no", // Implies this VR device is definitely not supported regardless of browser
  maybe: "maybe" // Implies this device may support this VR platform, but may not be installed or in a compatible browser
};

function isMaybeGearVRCompatibleDevice(ua) {
  return /\WAndroid\W/.test(ua);
}

function isMaybeDaydreamCompatibleDevice(ua) {
  return /\WAndroid\W/.test(ua);
}
github UnicornTranscoder / UnicornLoadBalancer / src / core / images.js View on Github external
...((query.width) ? { width: parseInt(query.width) } : {}),
        ...((query.height) ? { height: parseInt(query.height) } : {}),
        ...((query.background) ? { background: query.background } : {}),
        ...((query.opacity) ? { opacity: parseInt(query.opacity) } : {}),
        ...((query.minSize) ? { minSize: parseInt(query.minSize) } : {}),
        ...((query.blur) ? { blur: parseInt(query.blur) } : {}),
        ...((query.format && (query.format === 'webp' || query.format === 'png')) ? { format: query.format } : { format: 'jpg' }),
        ...((query.upscale) ? { upscale: parseInt(query.upscale) } : {}),
        ...((query.quality) ? { quality: parseInt(query.quality) } : ((query.blur) ? { quality: 100 } : { quality: 70 })),
        alpha: (query.format === 'png'),
        ...((query['X-Plex-Token']) ? { "X-Plex-Token": query['X-Plex-Token'] } : {}),
        url
    };

    // Auto select WebP if user-agent support it
    const browser = parseUserAgent(useragent);
    if (browser && browser.name && browser.name === 'chrome' && !query.format) {
        params.format = 'webp';
    }

    // Generate key
    params.key = md5(`${(query.url || '').split('?')[0]}|${params.width || ''}|${params.height || ''}|${params.background || ''}|${params.opacity || ''}|${params.minSize || ''}|${params.blur || ''}|${params.format || ''}|${params.upscale || ''}|${params.quality || ''}`.toLowerCase())

    // Return params
    return params;
}
github veteransaffairscanada / vac-benefits-directory / server.js View on Github external
server.get("*", (req, res) => {
      // Check if browse is less than IE 11
      const ua = req.headers["user-agent"];
      const browser = parseUserAgent(ua);
      const lang = req.query.lng
        ? req.query.lng
        : req.headers["accept-language"];

      req.data = data;
      req.language = lang ? lang.split(",")[0] : "en";
      if (
        browser &&
        browser.name === "ie" &&
        parseInt(browser.version) < 11 &&
        !req.url.includes("all-benefits") &&
        !req.url.includes(".css")
      ) {
        res.sendFile("fallback-pages/browser-incompatible.html", {
          root: __dirname
        });
github JimmyVV / httplive / src / httpflv / src / index.js View on Github external
constructor(url = '', config = {}) {
        super();

        this._browser = detect();


        // replace the object
        if (typeof url === 'object') {
            config = url;
        } else if (typeof url === 'string') {
            this._url = url;
        }


        switch (this._browser && this._browser.name) {
            case 'chrome':
            case "safari":
                this._xhr = new FetchChunked(config);
                break;
            case 'firefox':
github silverstripe / silverstripe-admin / client / src / lib / browserWarning.js View on Github external
/* global document */
import browser from 'detect-browser';

if (browser.name === 'ie' && parseInt(browser.version, 10) <= 10) {
  const warning = document.getElementById('browser-warning-wrapper');
  if (warning) {
    warning.className = `${warning.className} browser-warning-wrapper--incompatible`;
  }
}
github rtc-io / rtc-captureconfig / capabilities.js View on Github external
'use strict';

var browser = require('detect-browser');
var compareVersions = require('compare-versions')

var capabilities = module.exports = {
	moz: typeof navigator != 'undefined' && !!navigator.mozGetUserMedia,
	browser: browser.name,
	browserVersion: browser.version
};

// Mozilla constraings handling
if (capabilities.moz) {
	capabilities.constraintsType = (compareVersions(browser.version, '38.0.0') >= 0 ? 'standard' : 'legacy');
}
// Chrome constraints handling
else if (browser.name === 'chrome') {
	capabilities.constraintsType = (compareVersions(browser.version, '53.0.0') >= 0 ? 'standard' : 'legacy');
}
// Safari constraints handling
else if (browser.name === 'safari') {
	capabilities.constraintsType = (compareVersions(browser.version, '605.1.15') >= 0 ? 'standard' : 'legacy');
}
// Default constraints handling
else {
github rtc-io / rtc-captureconfig / capabilities.js View on Github external
moz: typeof navigator != 'undefined' && !!navigator.mozGetUserMedia,
	browser: browser.name,
	browserVersion: browser.version
};

// Mozilla constraings handling
if (capabilities.moz) {
	capabilities.constraintsType = (compareVersions(browser.version, '38.0.0') >= 0 ? 'standard' : 'legacy');
}
// Chrome constraints handling
else if (browser.name === 'chrome') {
	capabilities.constraintsType = (compareVersions(browser.version, '53.0.0') >= 0 ? 'standard' : 'legacy');
}
// Safari constraints handling
else if (browser.name === 'safari') {
	capabilities.constraintsType = (compareVersions(browser.version, '605.1.15') >= 0 ? 'standard' : 'legacy');
}
// Default constraints handling
else {
	capabilities.constraintsType = 'legacy';
}
github jirokun / survey-designer-js / lib / browserUtils.js View on Github external
export function isIELowerEquals(version) {
  // browserが定義されていないときは未知のブラウザ
  if (!browser) return false;
  return browser.name === 'ie' && parseInteger(browser.version.substr(0, browser.version.indexOf('.'))) <= version;
}
github mozilla / hubs / src / hub.js View on Github external
await store.initProfile();

  const canvas = document.querySelector(".a-canvas");
  canvas.classList.add("a-hidden");

  warmSerializeElement();

  if (!window.WebAssembly) {
    remountUI({ showWebAssemblyDialog: true });
    return;
  }

  // If we are on iOS but we don't have the mediaDevices API, then we are likely in a Firefox or Chrome WebView,
  // or a WebView preview used in apps like Twitter and Discord. So we show the dialog that tells users to open
  // the room in the real Safari.
  const detectedOS = detectOS(navigator.userAgent);
  if (detectedOS === "iOS" && !navigator.mediaDevices) {
    remountUI({ showSafariDialog: true });
    return;
  }

  // HACK: On Safari for iOS & MacOS, if mic permission is not granted, subscriber webrtc negotiation fails.
  // So we need to insist on microphone grants to continue.
  const browser = detect();
  if (["iOS", "Mac OS"].includes(detectedOS) && ["safari", "ios"].includes(browser.name)) {
    try {
      await navigator.mediaDevices.getUserMedia({ audio: true });
    } catch (e) {
      remountUI({ showSafariMicDialog: true });
      return;
    }
  }

detect-browser

Unpack a browser type and version from the useragent string

MIT
Latest version published 2 years ago

Package Health Score

74 / 100
Full package analysis