/
browser.ts
48 lines (45 loc) · 1.52 KB
/
browser.ts
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
import {detect} from 'detect-browser';
export const SUPPORTED_FIREFOX_VERSION = 57;
export const SUPPORTED_CHROME_VERSION = 64;
export const SUPPORTED_EDGE_VERSION = 16;
/**
* @internal
*/
export function getUnsupportedBrowserError() {
const info = detect();
if (!info) {
return 'browser cannot be detected';
}
const prefix = `unsupported browser detected:`;
switch(info.name) {
case 'firefox':
const fVersion = parseInt(info.version.slice(0, info.version.indexOf('.')), 10);
if(fVersion <= SUPPORTED_FIREFOX_VERSION && fVersion !== 52) { // ESR
return `${prefix} Firefox ${info.version} (< ${SUPPORTED_FIREFOX_VERSION})`;
}
return null;
case 'edge':
const eVersion = parseInt(info.version.slice(0, info.version.indexOf('.')), 10);
if(eVersion <= SUPPORTED_EDGE_VERSION) {
return `${prefix} Edge ${info.version} (< ${SUPPORTED_EDGE_VERSION})`;
}
return null;
case 'chrome':
const cVersion = parseInt(info.version.slice(0, info.version.indexOf('.')), 10);
if(cVersion <= SUPPORTED_CHROME_VERSION) {
return `${prefix} Chrome ${info.version} (< ${SUPPORTED_CHROME_VERSION})`;
}
return null;
case 'ie':
return `${prefix} Internet Explorer`;
}
console.warn('unknown browser detected', info, 'assuming fine...');
return null;
}
/**
* checks whether the current browser is compatible with lineupjs
* @return boolean
*/
export function isBrowserSupported() {
return getUnsupportedBrowserError() == null;
}