jakearchibald / idb

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

NotFoundError on Firefox Developer Edition v66 #92

Closed dnhyde closed 5 years ago

dnhyde commented 5 years ago

I am using Firefox Developer Edition (66.0b10) and idb v3.0.2.

When opening the db withidb.openDb("my-indexed-db", 1, function(upgradeDb)

I have the following error:

NotFoundError: The operation failed because the requested database object could not be found. For example, an object store did not exist but was being opened.

This error seems to be similar to what reported for firebase auth .

The exact same code works just fine in Firefox 62.0.3 (statndard edition). Still the same code, after updating to Firefox 65.0.1 (standard edition), produces the following error:

ConstraintError: A mutation operation in the transaction failed because a constraint was not satisfied.
AbortError: A request was aborted, for example through a call to IDBTransaction.abort.

Maybe as soon as Firefox hits v66 we shall see the first error pop out in the standard edition as well... (New features are stabilized for 12 weeks before appearing in the released version of Firefox. As MDN says here).

Hope this helps!

jakearchibald commented 5 years ago

https://static-misc.glitch.me/idb-basic/ this works for me in both Firefox Nightly and developer edition. Is it failing for you?

If it's failing, I'm 99% sure this is a Firefox bug. The library doesn't do anything special here.

dnhyde commented 5 years ago

Yes it works thanks I will switch to async await for now I am using promises Now I am not able to reproduce the first error and I am sure there is no diff in my code... The second error is due to an add instead of a put silly me!

The code that produced the error is the following, let me know if you notice anything weird... Thanks :)

const initDB = function() {
  //check for support
  if (!("indexedDB" in window)) {
    console.log("This browser doesn't support IndexedDB");
    return;
  }

  let dbPromise = idb.openDb("my-indexed-db", 1, function(upgradeDb) {
    if (!upgradeDb.objectStoreNames.contains("users")) {
      let users = upgradeDb.createObjectStore("users", { keyPath: "idFb" });
      users.createIndex("email", "email", { unique: true });
    }
  });

  dbPromise
    .then(db => {
      let tx = db.transaction("users", "readwrite");
      let users = tx.objectStore("users");

      //USERS is fetched from backend
      USERS.map(u => users.put(u));

      return tx.complete;
    })
    .then(function() {
      console.log("added users to the users objectStore of indexedDB!");
    });
};

initDB();

I will let you know if the first error comes up again sorry