Skip to content

Instantly share code, notes, and snippets.

@bennycode
Last active April 26, 2018 13:43
Show Gist options
  • Select an option

  • Save bennycode/1786e1f077d4bd1f1b6ccc7bf447949f to your computer and use it in GitHub Desktop.

Select an option

Save bennycode/1786e1f077d4bd1f1b6ccc7bf447949f to your computer and use it in GitHub Desktop.
Check if Firefox is in private mode
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