new Promise(function(resolve) { var db, on = function() { resolve(true) }, // is in private mode off = function() { resolve(false) }, // not private mode tryls = function() { try { localStorage.length ? off() : (localStorage.x = 1, localStorage.removeItem('x'), off()); } catch (e) { // Safari only enables cookie in private mode // if cookie is disabled then all client side storage is disabled // if all client side storage is disabled, then there is no point // in using private mode navigator.cookieEnabled ? on() : off(); } } // Chrome & Opera window.webkitRequestFileSystem ? webkitRequestFileSystem(0, 0, off, on) // Firefox : 'MozAppearance' in document.documentElement.style ? (db = indexedDB.open('test'), db.onerror = on, db.onsuccess = off) // Safari : (/constructor/i).test(window.HTMLElement) ? tryls() // IE10+ & Edge : !window.indexedDB && (window.PointerEvent || window.MSPointerEvent) ? on() // Rest : off(); }).then(function(isPrivateMode) { console.log('Private mode is: ' + isPrivateMode) });