forked from Expensify/expensify-common
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBrowserDetect.jsx
91 lines (85 loc) · 2.11 KB
/
BrowserDetect.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
const BROWSERS = {
EDGE: 'Edge',
CHROME: 'Chrome',
SAFARI: 'Safari',
OPERA: 'Opera',
EXPLORER: 'Explorer',
MOZILLA: 'Mozilla'
};
const MOBILE_PLATFORMS = {
iOS: 'iOS',
android: 'android'
};
function searchString() {
const data = [{
string: navigator.userAgent,
subString: 'Edge',
identity: BROWSERS.EDGE
}, {
string: navigator.userAgent,
subString: 'Chrome',
identity: BROWSERS.CHROME
}, {
string: navigator.vendor,
subString: 'Apple',
identity: BROWSERS.SAFARI,
}, {
prop: window.opera,
identity: BROWSERS.OPERA,
}, {
string: navigator.userAgent,
subString: 'Edge',
identity: BROWSERS.EDGE
}, {
string: navigator.userAgent,
subString: 'MSIE',
identity: BROWSERS.EXPLORER
}, {
string: navigator.userAgent,
subString: '.NET',
identity: BROWSERS.EXPLORER
}, {
string: navigator.userAgent,
subString: 'Gecko',
identity: BROWSERS.MOZILLA
}];
let dataString;
let dataProp;
for (let i = 0; i < data.length; i++) {
dataString = data[i].string;
dataProp = data[i].prop;
if (dataString) {
if (dataString.indexOf(data[i].subString) !== -1) {
return data[i].identity;
}
} else if (dataProp) {
return data[i].identity;
}
}
return '';
}
function getMobileDevice() {
const data = [{
devices: ['iPhone', 'iPad', 'iPod'],
identity: MOBILE_PLATFORMS.iOS
}, {
devices: ['Android'],
identity: MOBILE_PLATFORMS.android
}];
const dataString = navigator.userAgent;
for (let i = 0; i < data.length; i++) {
const {devices, identity} = data[i];
for (let j = 0; j < devices.length; j++) {
if (dataString.indexOf(devices[j]) !== -1) {
return identity;
}
}
}
return '';
}
export default {
BROWSERS,
MOBILE_PLATFORMS,
browser: searchString(),
mobileDevice: getMobileDevice()
};