w3c / IndexedDB

Indexed Database API
https://w3c.github.io/IndexedDB/
Other
240 stars 62 forks source link

Specify behavior when document is not fully active #412

Open inexorabletash opened 1 year ago

inexorabletash commented 1 year ago

Related to #381

  1. navigate to https://example.com/ (or anything really)
  2. open devtools/inspector/console/etc
  3. i = document.createElement('iframe');
  4. i.src = location;
  5. document.body.append(i);
  6. ii = i.contentWindow.indexedDB;
  7. ii.open('db'); - returns IDBOpenDBRequest
  8. i.remove();
  9. ii.open('db'); - returns ???

In Chrome this returns null. Throwing is probably more correct behavior. I haven't tested in other browsers.

asutherland commented 1 year ago

In Firefox we return our unknown error because we cleared the global from the factory when the iframe's window was cleaned up. In Firefox devtools this looks like:

DOMException: The operation failed for reasons unrelated to the database itself and not covered by any other error code.

We can probably improve the exception message we throw in Firefox at least.

Throwing seems appropriate for a case like this where the API does not return a Promise.

inexorabletash commented 1 year ago

Agreed re: throwing.

For web locks it's spec'd to reject with an "InvalidStateError" DOMException, which seems reasonable to me. I'd prefer to reserve UnknownError for cases when we're in unspecable/untestable territory, whereas this is just an edge case but totally specable/testable. I don't feel strongly about it though.

FWIW, in Chrome localStorage.getItem() throws a "SecurityError" DOMException and caches.open() returns undefined (not a Promise!). Wheee.

asutherland commented 1 year ago

Yes, InvalidStateError seems better and we're fine to change Firefox's behavior here (and have tests that enforce that as the right exception). Thanks!

attila-lendvai commented 1 year ago

FWIW, i'm also getting this error with the MetaMask extension, and it completely fails to start now.

UnknownError: The operation failed for reasons unrelated to the database itself and not covered by any other error code.

i have zero clue what goes wrong, where, and how to fix it. deleting the storage would mean hours of work lost.

asutherland commented 1 year ago

FWIW, i'm also getting this error with the MetaMask extension, and it completely fails to start now.

UnknownError: The operation failed for reasons unrelated to the database itself and not covered by any other error code.

This sounds browser specific. If this is on Firefox, please file a bug against our IndexedDB component and I can respond there. If this is on another browser, please file against that browser (or the MetaMask extension).