-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1fb5be3
commit fc5f99b
Showing
3 changed files
with
14 additions
and
23 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,42 @@ | ||
import CONST from '../../CONST'; | ||
|
||
/** | ||
* fetch Browser Name and version from UA string | ||
* fetch Browser name from UA string | ||
* | ||
* @return {String} e.g. Chrome 80 | ||
* @return {String} e.g. Chrome | ||
*/ | ||
function getBrowserVersion() { | ||
function getBrowser() { | ||
const {userAgent} = window.navigator; | ||
let match = userAgent.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || []; | ||
let match = userAgent.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))/i) || []; | ||
let temp; | ||
|
||
if (/trident/i.test(match[1])) { | ||
temp = /\brv[ :]+(\d+)/g.exec(userAgent) || []; | ||
|
||
return `IE ${temp[1] || ''}`; | ||
return 'IE'; | ||
} | ||
|
||
if (match[1] === 'Chrome') { | ||
if (match[1] && (match[1].toLowerCase() === 'chrome')) { | ||
temp = userAgent.match(/\b(OPR|Edge)\/(\d+)/); | ||
|
||
if (temp !== null) { | ||
return temp.slice(1).join(' ').replace('OPR', 'Opera'); | ||
return temp.slice(1).replace('OPR', 'Opera'); | ||
} | ||
|
||
temp = userAgent.match(/\b(Edg)\/(\d+)/); | ||
|
||
if (temp !== null) { | ||
return temp.slice(1).join(' ').replace('Edg', 'Edge'); | ||
return temp.slice(1).replace('Edg', 'Edge'); | ||
} | ||
} | ||
|
||
match = match[2] ? [match[1], match[2]] : [navigator.appName, navigator.appVersion, '-?']; | ||
temp = userAgent.match(/version\/(\d+)/i); | ||
|
||
if (temp !== null) { | ||
match.splice(1, 1, temp[1]); | ||
} | ||
|
||
return match.join(' '); | ||
match = match[1] ? match[1] : navigator.appName; | ||
return match; | ||
} | ||
|
||
/** | ||
* Get the Browser name | ||
* @returns {String} | ||
*/ | ||
export default () => { | ||
const browserAndVersion = getBrowserVersion(); | ||
const [browser] = browserAndVersion.split(' '); | ||
const browser = getBrowser(); | ||
return browser ? browser.toLowerCase() : CONST.BROWSER.OTHER; | ||
}; |