Created
June 5, 2018 10:54
-
-
Save romanzaycev/05db43cb18bddec9d25331ed97030ab5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isIncognitoMode() { | |
return new Promise(function(resolve, reject) { | |
var fs = window.RequestFileSystem || window.webkitRequestFileSystem; | |
if (fs) { | |
fs( | |
window.TEMPORARY, | |
100, | |
function (fs) { | |
resolve(false); | |
}, function (err) { | |
resolve(true); | |
} | |
); | |
return; | |
} | |
if (window.indexedDB) { | |
var db = indexedDB.open("incognito_test"); | |
db.onerror = function() { | |
resolve(true); | |
}; | |
return; | |
} | |
if (!window.indexedDB && (window.PointerEvent || window.MSPointerEvent)) { | |
resolve(true); | |
return; | |
} | |
var storage = window.sessionStorage; | |
try { | |
storage.setItem("incognito_test", "test"); | |
storage.removeItem("incognito_test"); | |
} catch (e) { | |
if (e.code === DOMException.QUOTA_EXCEEDED_ERR && storage.length === 0) { | |
resolve(true); | |
return; | |
} | |
} | |
resolve(false); | |
}); | |
} | |
isIncognitoMode() | |
.then(function(result){ | |
console.log(result ? "Incognito" : "Not incognito"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment