jakearchibald / idb

IndexedDB, but with promises
https://www.npmjs.com/package/idb
ISC License
6.4k stars 360 forks source link

InvalidStateError: A mutation operation was attempted on a database that did not allow mutations. #81

Closed viniciuscr closed 5 years ago

viniciuscr commented 5 years ago

Hi, I am struggling with an error trying to create the database It works only on Chrome, Firefox gives the error: InvalidStateError: A mutation operation was attempted on a database that did not allow mutations. MS Edge does not work at all.

My code is something like this:

STORE = "storeName";
VERSION = 1;

  dbPromise = openDb("dbName", this.VERSION, upgradeDB =>
      upgradeDB
        .createObjectStore(this.STORE, { keyPath: "name" })
        .createIndex("name", "name", { unique: true })
    );
viniciuscr commented 5 years ago

Ok i got the problem with Firefox. I was using Firefox with anonymous tab and it don´t let you store anything, but Edge still a issue.

jakearchibald commented 5 years ago

Please reopen if you get the same issue with 4.0.0

nico-martin commented 5 years ago

Unfortunately this is not solved yet. I think the problem is that FF in private mode does not support IndexedDB at all. Is there a way to create a workaround or to detect that IndexedDB is no available? https://bugzilla.mozilla.org/show_bug.cgi?id=781982

codinronan commented 4 years ago

I know this is an old issue but I'm building a layer for an app I'm working on and I want to be able to provide a fallback in-memory database on browsers that block IDB in private browsing (Firefox).

The problem is that Firefox exposes the indexedDb object on window but you can't use it, so simply using if (!window.indexedDb) is not an option -- the only way to know is to attempt a database open operation.

However unfortunately since IDB's openDb function swallows the exception, it's not possible -- I need a completely separate check against a different database name in order to validate support.

Any way we could allow that exception through, or include a supported helper?

jakearchibald commented 4 years ago

What do you mean by "swallows the error"? That error should carry through as a promise rejection.

codinronan commented 4 years ago

@jakearchibald sorry you're right, I didn't read enough code. The catch on this line catches the sub-promise, not the outer one. The exception will escape as intended.

Thanks!