Skip to content

Instantly share code, notes, and snippets.

@dsheiko
Created July 16, 2018 16:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save dsheiko/bd6a3a73c4b1fd9140e5b102c5cbcdb0 to your computer and use it in GitHub Desktop.
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