is-private-navigation
Version:
detect Incognito Mode navigation
1 lines • 1.12 kB
JavaScript
function isPrivateMode(){return new Promise(function(resolve){const yes=function(){return resolve(true)};const not=function(){return resolve(false)};const testSafariLesserThan11=function(){try{if(localStorage.length)not();else{localStorage.x=1;localStorage.removeItem("x");not()}}catch(e){navigator.cookieEnabled?yes():not()}};if(window.chrome){if("storage"in navigator&&"estimate"in navigator.storage){navigator.storage.estimate().then(function(ram){if(ram.quota<120000000){yes()}else{not()}})}}var fs=window.webkitRequestFileSystem||window.RequestFileSystem;if(fs){return void fs(window.TEMPORARY,100,not,yes)}if("MozAppearance"in document.documentElement.style){if(indexedDB===null)return yes();const db=indexedDB.open("test");db.onerror=yes;db.onsuccess=not;return void 0}const isSafari=navigator.userAgent.match(/Version\/([0-9\._]+).*Safari/);if(isSafari){const version=parseInt(isSafari[1],10);if(version<11)return testSafariLesserThan11();try{window.openDatabase(null,null,null,null);return not()}catch(_){return yes()}}if(!window.indexedDB&&(window.PointerEvent||window.MSPointerEvent)){return yes()}return not()})}