Last active
April 26, 2018 13:43
-
-
Save bennycode/1786e1f077d4bd1f1b6ccc7bf447949f to your computer and use it in GitHub Desktop.
Check if Firefox is in private mode
This file contains hidden or 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
| var isInPrivateMode = () => { | |
| if (!window.indexedDB) { | |
| return Promise.resolve(false); | |
| } else { | |
| return new Promise((resolve, reject) => { | |
| const name = 'test'; | |
| const DBOpenRequest = window.indexedDB.open(name); | |
| DBOpenRequest.onerror = () => resolve(true); | |
| DBOpenRequest.onsuccess = () => { | |
| const db = DBOpenRequest.result; | |
| db.close(); | |
| const deleteRequest = window.indexedDB.deleteDatabase(name); | |
| deleteRequest.onerror = () => reject(); | |
| deleteRequest.onsuccess = () => resolve(false); | |
| }; | |
| }).catch(() => Promise.resolve(true)); | |
| } | |
| } | |
| isInPrivateMode() | |
| .then((isInPrivateMode) => console.log(`Private mode: ${isInPrivateMode}`)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment