-
Notifications
You must be signed in to change notification settings - Fork 8
/
PrivateWindowCheck.js
84 lines (79 loc) · 2.16 KB
/
PrivateWindowCheck.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
async function chrome76Detection() {
if ('storage' in navigator && 'estimate' in navigator.storage) {
const {usage, quota} = await navigator.storage.estimate();
if(quota < 120000000)
return true;
else
return false;
} else {
return false;
}
}
function isNewChrome () {
var pieces = navigator.userAgent.match(/Chrom(?:e|ium)\/([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/);
if (pieces == null || pieces.length != 5) {
return undefined;
}
major = pieces.map(piece => parseInt(piece, 10))[1];
if(major >= 76)
return true
return false;
}
var PrivateWindow = new Promise(function (resolve, reject) {
try {
var isSafari = navigator.vendor && navigator.vendor.indexOf('Apple') > -1 &&
navigator.userAgent &&
navigator.userAgent.indexOf('CriOS') == -1 &&
navigator.userAgent.indexOf('FxiOS') == -1;
if(isSafari){
//Safari
var e = false;
if (window.safariIncognito) {
e = true;
} else {
try {
window.openDatabase(null, null, null, null);
window.localStorage.setItem("test", 1)
resolve(false);
} catch (t) {
e = true;
resolve(true);
}
void !e && (e = !1, window.localStorage.removeItem("test"))
}
} else if(navigator.userAgent.includes("Firefox")){
//Firefox
var db = indexedDB.open("test");
db.onerror = function(){resolve(true);};
db.onsuccess =function(){resolve(false);};
} else if(navigator.userAgent.includes("Edge") || navigator.userAgent.includes("Trident") || navigator.userAgent.includes("msie")){
//Edge or IE
if(!window.indexedDB && (window.PointerEvent || window.MSPointerEvent))
resolve(true);
resolve(false);
} else { //Normally ORP or Chrome
//Other
if(isNewChrome())
resolve(chrome76Detection());
const fs = window.RequestFileSystem || window.webkitRequestFileSystem;
if (!fs) resolve(null);
else {
fs(window.TEMPORARY, 100, function(fs) {
resolve(false);
}, function(err) {
resolve(true);
});
}
}
}
catch(err) {
console.log(err);
resolve(null);
}
});
function isPrivateWindow(callback) {
PrivateWindow.then(function(is_private) {
console.log(is_private);
callback(is_private);
});
}