This gist demonstrates a problem with IndexedDB & Promises in Firefox which makes using IndexedDB very unergonomic in some cases in Firefox.
The test below reads, updates & writes a counter value to an IndexedDB database 10 times in the same transaction and then prints the result. To make the code easier to read, it uses async + await, which requires converting the IndexedDB requests (IDBRequest
objects) to promises with a simple helper.
In Chrome, multiple promise callbacks can be executed with auto-committing an IDB transaction, allowing read-modify-write steps to work. In Firefox however, the IDB transaction gets auto-committed before the promise callback is fired, which means that read-modify-write operations have to use callbacks rather than promises.