Created
April 10, 2019 10:15
-
-
Save sankarseran/71e3fa5bea9572f71c5a319046ee344b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
detectBrowser: function(window) { | |
var navigator = window && window.navigator; | |
// Returned result object. | |
var result = {}; | |
result.browser = null; | |
result.version = null; | |
// Fail early if it's not a browser | |
if (typeof window === 'undefined' || !window.navigator) { | |
result.browser = 'Not a browser.'; | |
return result; | |
} | |
if (navigator.mozGetUserMedia) { // Firefox. | |
result.browser = 'firefox'; | |
result.version = extractVersion(navigator.userAgent, | |
/Firefox\/(\d+)\./, 1); | |
} else if (navigator.webkitGetUserMedia) { | |
// Chrome, Chromium, Webview, Opera. | |
// Version matches Chrome/WebRTC version. | |
result.browser = 'chrome'; | |
result.version = extractVersion(navigator.userAgent, | |
/Chrom(e|ium)\/(\d+)\./, 2); | |
} else if (navigator.mediaDevices && | |
navigator.userAgent.match(/Edge\/(\d+).(\d+)$/)) { // Edge. | |
result.browser = 'edge'; | |
result.version = extractVersion(navigator.userAgent, | |
/Edge\/(\d+).(\d+)$/, 2); | |
} else if (window.RTCPeerConnection && | |
navigator.userAgent.match(/AppleWebKit\/(\d+)\./)) { // Safari. | |
result.browser = 'safari'; | |
result.version = extractVersion(navigator.userAgent, | |
/AppleWebKit\/(\d+)\./, 1); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment