Skip to content

Instantly share code, notes, and snippets.

@ckybonist
Last active November 2, 2020 07:34
Show Gist options
  • Select an option

  • Save ckybonist/178779ee60b0fbd50fdee0d02048b9a6 to your computer and use it in GitHub Desktop.

Select an option

Save ckybonist/178779ee60b0fbd50fdee0d02048b9a6 to your computer and use it in GitHub Desktop.
Prevent old Firefox (e.g. 54.0) throw InvalidStateError by default in private mode
function debug(showError = true) {
if (window.indexedDB) {
try {
const request = window.indexedDB.open('demo', 1);
request.onsuccess = function (event) {
// not raised
};
request.onupgradeneeded = function (event) {
// not raised
};
request.onerror = function (event) {
if (!request.error) return;
if (request.error.name === 'InvalidStateError' && !showError) {
// raised with no InvalidStateError
event.preventDefault();
}
};
} catch(error) {
console.error(error);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment