UPDATED : Chrome has been further developed and no longer leaves room for detection when using incognito mode.
Private browsing modes can be detected for most browsers in use. This includes Safari, Firefox, IE10, Edge, and Google Chrome.
Firefox
When Firefox's private browsing mode is enabled, IndexedDB throws an InvalidStateError because it is not available in private browsing mode.
Very, if that:
var db = indexedDB.open("test"); db.onerror = function(){}; db.onsuccess =function(){};
Safari
For Safari, the key is the local storage service. This is disabled in privacy mode. So try to access it and use the try-catch clause. The following method works on OSX and iOS devices. Loans for this method are collected for this question and answer.
var storage = window.sessionStorage; try { storage.setItem("someKeyHere", "test"); storage.removeItem("someKeyHere"); } catch (e) { if (e.code === DOMException.QUOTA_EXCEEDED_ERR && storage.length === 0) {
IE10 / Edge
Internet Explorer is even about to disable IndexedDB in privacy mode. So check for existence. But this is not enough, because older browsers may not even have IDBs. So do one more check, for example for events that are only in IE10 and subsequent browsers. The relevant question on CodeReview can be found here.
if(!window.indexedDB && (window.PointerEvent || window.MSPointerEvent)){
Chrome
Update : this does not work with Chrome 76 (thanks @jLynx)
Chromes incognito mode can be checked by the file system. A great explanation can be found here on SO
var fs = window.RequestFileSystem || window.webkitRequestFileSystem; if (!fs) { console.log("FS check failed.."); return; } fs(window.TEMPORARY, 100, function (fs) {}, function (err) {
manniL Dec 25 '16 at 15:00 2016-12-25 15:00
source share