1 | import { detect } from 'detect-browser';
|
2 |
|
3 | export const SUPPORTED_FIREFOX_VERSION = 57;
|
4 | export const SUPPORTED_CHROME_VERSION = 64;
|
5 | export const SUPPORTED_EDGE_VERSION = 16;
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | export 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 |
|
21 | return `${prefix} Firefox ${info.version} (< ${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} (< ${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} (< ${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 |
|
44 |
|
45 |
|
46 | export function isBrowserSupported() {
|
47 | return getUnsupportedBrowserError() == null;
|
48 | }
|