This repository has been archived by the owner on Jan 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
unsupported-utils.js
59 lines (49 loc) · 1.57 KB
/
unsupported-utils.js
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
import { browser, os, bots } from '@jam3/detect';
import deviceMatrix from './device-matrix.json';
/**
* Returns if the current browser is supported by the web app
* The algorithm is inclusive, so we enumerate everything we don't support, after that everything is supported
*
* @returns {Boolean} supported
*/
function isSupported() {
const userBrowser = browser.getName().toLowerCase();
const userBrowserVersion = parseFloat(browser.getVersion());
const userOS = os ? os.getName().toLowerCase() : 'unknown';
const userOSVersion = os.getVersion() === 'Unknown' ? Number.MAX_SAFE_INTEGER : parseFloat(os.getVersion());
if (bots.isBot()) {
return true;
}
const supportedOsVersion = deviceMatrix[userOS];
const supportedBrowserVersion = deviceMatrix[userBrowser];
const supportedVersion = supportedBrowserVersion || supportedOsVersion;
if (supportedVersion) {
if (supportedOsVersion !== undefined) {
if (userOSVersion < supportedOsVersion) {
return false;
}
}
if (supportedBrowserVersion !== undefined) {
/* Special contrains here */
if (userBrowserVersion < supportedBrowserVersion) {
return false;
}
}
}
return true;
}
/**
* Print current browser information
*
* @returns {String} Browser|Browser Version|OS|OS Version|UA
*/
function getBrowserInformation() {
return `
browser: ${browser.getName()},
browser version: ${browser.getVersion()},
os: ${os.getName()},
os version: ${os.getVersion()},
ua: ${navigator.userAgent}
`;
}
export { isSupported, getBrowserInformation };