UNPKG

1.61 kBPlain TextView Raw
1import { detect } from 'detect-browser';
2
3export const SUPPORTED_FIREFOX_VERSION = 57;
4export const SUPPORTED_CHROME_VERSION = 64;
5export const SUPPORTED_EDGE_VERSION = 16;
6
7/**
8 * @internal
9 */
10export function getUnsupportedBrowserError() {
11 const info = detect();
12 if (!info || !info.version) {
13 return 'browser cannot be detected';
14 }
15 const prefix = `unsupported browser detected:`;
16 switch (info.name) {
17 case 'firefox':
18 const fVersion = Number.parseInt(info.version.slice(0, info.version.indexOf('.')), 10);
19 if (fVersion <= SUPPORTED_FIREFOX_VERSION && fVersion !== 52) {
20 // ESR
21 return `${prefix} Firefox ${info.version} (&lt; ${SUPPORTED_FIREFOX_VERSION})`;
22 }
23 return null;
24 case 'edge':
25 const eVersion = Number.parseInt(info.version.slice(0, info.version.indexOf('.')), 10);
26 if (eVersion <= SUPPORTED_EDGE_VERSION) {
27 return `${prefix} Edge ${info.version} (&lt; ${SUPPORTED_EDGE_VERSION})`;
28 }
29 return null;
30 case 'chrome':
31 const cVersion = Number.parseInt(info.version.slice(0, info.version.indexOf('.')), 10);
32 if (cVersion <= SUPPORTED_CHROME_VERSION) {
33 return `${prefix} Chrome ${info.version} (&lt; ${SUPPORTED_CHROME_VERSION})`;
34 }
35 return null;
36 case 'ie':
37 return `${prefix} Internet Explorer`;
38 }
39 console.warn('unknown browser detected', info, 'assuming fine...');
40 return null;
41}
42/**
43 * checks whether the current browser is compatible with lineupjs
44 * @return boolean
45 */
46export function isBrowserSupported() {
47 return getUnsupportedBrowserError() == null;
48}