Created
July 16, 2018 16:13
-
-
Save dsheiko/bd6a3a73c4b1fd9140e5b102c5cbcdb0 to your computer and use it in GitHub Desktop.
decorated for older browsers https://gist.github.com/jherax/a81c8c132d09cc354a0e2cb911841ff1
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 isPrivateMode() { | |
return new Promise((resolve) => { | |
const on = function(){ resolve( true ); } | |
const off = function(){ resolve(false); } | |
const testLocalStorage = function(){ | |
try { | |
if ( localStorage.length ) { | |
off(); | |
return; | |
} | |
localStorage.x = 1; | |
localStorage.removeItem('x'); | |
off(); | |
} catch ( e ) { | |
navigator.cookieEnabled ? on() : off(); | |
} | |
}; | |
// Chrome | |
if ( window.webkitRequestFileSystem ) { | |
return void window.webkitRequestFileSystem( 0, 0, off, on ); | |
} | |
// FF | |
if ( "MozAppearance" in document.documentElement.style ) { | |
var db = indexedDB.open( "test" ); | |
db.onerror = on; | |
db.onsuccess = off; | |
return void 0; | |
} | |
// Safari | |
if ( /constructor/i.test( window.HTMLElement ) ) { | |
return testLocalStorage(); | |
} | |
// IE10+ & Edge | |
if ( !window.indexedDB && ( window.PointerEvent || window.MSPointerEvent ) ) { | |
return on(); | |
} | |
// others | |
return off(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment