-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
28 lines (24 loc) · 1.07 KB
/
index.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
if (navigator && navigator.userAgent) {
// 检测浏览器版本,并设置 window.__disableNativeFetch 来决定是否开启 fetch
var userAgent = navigator.userAgent || "";
var appVersion = navigator.appVersion || "";
var vendor = navigator.vendor || "";
var ua = (userAgent + ' ' + appVersion + ' ' + vendor).toLowerCase();
var match = /(chrome)[ \/]([\w.]+)/.exec(ua)
|| /(webkit)[ \/]([\w.]+)/.exec(ua)
|| /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua)
|| /(msie) ([\w.]+)/.exec(ua)
|| /(trident)(?:.*? rv:([\w.]+)|)/.exec(ua)
|| ua.indexOf("compatible") < 0
&& /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) || [];
var engine = match[0];
var mainVersion = match[2].split('.')[0];
// chrome 内核版本大于 46, firefox 版本大于39 才开启 fetch
if (engine.indexOf('chrome') === 0 && mainVersion >= 46) {
window.__disableNativeFetch = false;
} else if (engine.indexOf('mozilla') === 0 && mainVersion >= 39) {
window.__disableNativeFetch = false;
} else {
window.__disableNativeFetch = true;
}
}