I'm integrating a javascript library that uses IndexedDB, but it fails "ungraciously" when Firefox is in private browsing/window mode. The library returns out a 500 Internal Error and meanwhile Firefox spits out an InvalidStateError to console.
What I'd like to do is add a check before I instantiate this library, and not use the library at all if IndexedDB is not available. i.e. some type of try/catch test. From what I've seen, Firefox appears to spit out the console error even if the offending code is inside a try/catch (but maybe there's still a way..).
I don't actually have an interest whether the user is in a private window session or not, but that seems to be the only time when Firefox causes this InvalidStateError.
You have handle the errors in the onerror function.
This won't tell you for definite that the use is "In Private", but will tell you you can't use indexedDB - from which you could interpolate if you needed to - ie if its FireFox and this throws and error then chances are they are In Private - until the guys at Mozilla fix it.
var db = window.indexedDB.open('test');
db.onerror = function()
{
console.log("Can't use indexedDB")
}
This still kicks out the InvalidStateError to the console, but the js can handle the consequences.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With