Skip to content

Instantly share code, notes, and snippets.

@romanzaycev
Created June 5, 2018 10:54
Show Gist options
  • Save romanzaycev/05db43cb18bddec9d25331ed97030ab5 to your computer and use it in GitHub Desktop.
Save romanzaycev/05db43cb18bddec9d25331ed97030ab5 to your computer and use it in GitHub Desktop.
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