Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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