-
-
Save Ema4rl/d49bda878dc26455c5e8609adb345005 to your computer and use it in GitHub Desktop.
Detect private browsing mode (InPrivate Browsing or Incognito).
This file contains hidden or 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
"use strict"; | |
// check out https://jsfiddle.net/Lj2fs5kr/ | |
new Promise(function (resolve) { | |
var db = void 0, | |
on = function on() { | |
return resolve(true); | |
}, | |
off = function off() { | |
return resolve(false); | |
}, | |
tryls = function tryls() { | |
try { | |
localStorage.length ? off() : (localStorage.x = 1, localStorage.removeItem("x"), off()); | |
} catch (e) { | |
on(); | |
} | |
}; | |
// Blink | |
window.webkitRequestFileSystem ? webkitRequestFileSystem(window.TEMPORARY, 1, off, on) | |
// FF | |
: "MozAppearance" in document.documentElement.style ? (db = indexedDB.open("test"), db.onerror = on, db.onsuccess = off | |
// Safari | |
) : /constructor/i.test(window.HTMLElement) ? tryls() | |
// IE10+ & edge | |
: !window.indexedDB && (window.PointerEvent || window.MSPointerEvent) ? on() | |
// Rest | |
: off(); | |
}).then(function (enabled) { | |
document.body.innerHTML = enabled; | |
}); |
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
</head> | |
<body> | |
<script src="detect-private-browsing.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment