dexie / Dexie.js

A Minimalistic Wrapper for IndexedDB
https://dexie.org
Apache License 2.0
11.49k stars 642 forks source link

InvalidStateError on Firefox #312

Open julienfouilhe opened 8 years ago

julienfouilhe commented 8 years ago

Hi,

For some time now, I've seen a recurring error: InvalidStateError

InvalidStateError occurred when opening database database_name. A mutation operation was attempted on a database that did not allow mutations.

This happens with this simple code:

  var db = new Dexie('database_name');
  db.version(2).stores({ actions: '++_id, *scoreId, &id' });

  db.open().then(function() {
    // not entering there
  }.bind(this)).catch(function(err) {
    // catching invalid state error
  }.bind(this));

It only happens on Firefox (v39 to v48), rarely though. I was never able to reproduce it, I've only seen this happen to my users, via bug reporting.

I've seen this link that seems to be related but I can't figure out what I'm doing wrong: http://stackoverflow.com/questions/24295588/indexeddb-error-in-firefox-when-calling-createobjectstore

julienfouilhe commented 8 years ago

Seems to be produced when using private navigation. I guess this is related to the way Firefox handles storing data in private mode. Safari throws a MissingAPIError too.

I think that the fact that IndexedDB does not work in private mode for those browsers should be put forward in the documentation. It would save time to a lot of developers. Not Dexie's fault but nice to mention anyway! ;)

dfahlander commented 8 years ago

Ok, thanks for sharing this. I don't get why cookies are allowed but not indexedDB. Probably due to the lack of a RAM memory based indexeddb implementation.

I could write some doc about this issue and how to give users a better experience than just obscure error messages. It might be useful to update dexie to give a common error for errors due to private browsing. I'll see what I could do about it.

dev0x10 commented 7 years ago

When trying to set in private browser there will be an error thrown

DexieError {_e: Error, name: "OpenFailedError", message: "QuotaExceededError The quota has been exceeded.", inner: DexieError, _stack: "OpenFailedError: QuotaExceededError The quota has …/prototype.testing.com/app.bundle.js:53871:50", …}

That quota ExceededError is same error thrown when trying to use localStorage on Safari private browsing This means Dexie doesn't support private browsing, right?

julienfouilhe commented 7 years ago

@dev0x10 I've had this one too and it seems to mean that the user's disk is full and therefore browser denies opening a database

dev0x10 commented 7 years ago

@julienfouilhe oh yes user's disk full also can cause that problem. But mostly it is happen because of private browsing mode, especially in Safari I'd like to know if there is a workaround for using Dexie in private browsing mode

dev0x10 commented 7 years ago

Oh I found explanation here: http://stackoverflow.com/questions/38982914/dexie-indexeddb-mobile-private-browsing-error-uh-oh-missing-api-error-indexe

indolering commented 7 years ago

There really should be a more informative warning for when IndexedDB isn't available....

DemersM commented 7 years ago

People at Firefox are working (slowly) to fix the issue and to enable IndexedDB in private mode: https://bugzilla.mozilla.org/show_bug.cgi?id=781982

NelsonMinar commented 6 years ago

According to MDN docs the only browser that supports IndexedDB in private mode is Chrome. https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API#Browser_compatibility