Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Safari: Unhandled Promise Rejection: NotFoundError: Failed to execute 'transaction' on 'IDBDatabase': One of the specified object stores was not found. #134

Closed
getflourish opened this issue Oct 7, 2021 · 7 comments · May be fixed by #138

Comments

@getflourish
Copy link

getflourish commented Oct 7, 2021

Issue

Unhandled Promise Rejection: NotFoundError: Failed to execute 'transaction' on 'IDBDatabase': One of the specified object stores was not found.

How to replicate

macOS 11.6
Safari 15.0

When developing on localhost everything works initially. But once I deploy the code to a different domain, I tend to see this error. I don’t know what the error message is trying to tell me and how I can fix it. I have a feeling that some things are getting mixed up:

My setup:

  • My HTML document embeds an iframe.
  • The iframe’s document is accessing IndexedDB.
  • While the host of the outer document can vary, the URL of the iframe is the same.

In the web inspector under application storage, the domain of the host page is shown.

@getflourish
Copy link
Author

I’ve modified the code and try to debug. So the error is telling me that the IDBDatabase does exist, but the store keyval does not exist.

localhost

Here, the store exists.

image

production:

No store.

image

@getflourish
Copy link
Author

getflourish commented Oct 7, 2021

I think the onupgradeneeded is never called for some reason, thus the store isn’t created?

image

function createStore(dbName, storeName) {
  const dbp = idbReady().then(() => {
    const request = indexedDB.open(dbName);
    
    // Log #1
    console.log(request);
    request.onupgradeneeded = () => {
      // Log #2 is never called
      console.log("Create store", request.result);
      request.result.createObjectStore(storeName);
    };
    // Log #3
    console.warn("onupgradeneeded?");
    return promisifyRequest(request);
  });
  return (txMode, callback) =>
    dbp.then((db) => {
      callback(db.transaction(storeName, txMode).objectStore(storeName));
    });
}

@getflourish
Copy link
Author

getflourish commented Oct 7, 2021

Okay, this comment on MDN is interesting:

// This handler is called when a new version of the database
// is created, either when one has not been created before
// or when a new version number is submitted by calling
// window.indexedDB.open().
// This handler is only supported in recent browsers.
request.onupgradeneeded = function(event) {
  var db = event.target.result;
[]

So… I guess the handler isn’t called because the DB already exists, but apparently not with a store?

@getflourish
Copy link
Author

I’m trying to reproduce how I got into this state…

For now, I’ve fixed the issue be removing all relevant databases from ~Library/Safari/Databases/…

@jakearchibald
Copy link
Owner

It sounds like a database of the same name had already been created on that origin, but without the object store. Does that sound likely/possible?

@getflourish
Copy link
Author

Yes, that's what I'm seeing in Dev Tools: multiple keyval-store databases for the same domain. Is that correct or should there only ever be one?

@jakearchibald
Copy link
Owner

Only one, unless you've created many

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants