Mr. Tono's archive cabinet: IndexedDB requests, versions and transactions run for real, stepped in the browser's order. An interactive IndexedDB playground…
Why it matters
IndexedDB keeps real objects in large amounts without blocking the page, but its API is built on requests and events. Misreading the order, the versions or a transaction’s lifetime gives puzzling errors: InvalidStateError, TransactionInactiveError, data lost to an abort.
The key idea
Every call is a request; every errand is a transaction that closes itself
Common mistakes
Expecting get() to return the value directly like localStorage IndexedDB is request-based: get() returns a pendingIDBRequest. Read req.result in onsuccess, or wrap it in a Promise (the idb library, say).
Forgetting to create the store in onupgradeneeded Object stores can only be created as the version goes up (onupgradeneeded). Raise the version to change the schema; outside it createObjectStore throws InvalidStateError.
Operations on a transaction that has closed A transaction commits by itself when its task ends with no request pending. Do not keep one for later: after a setTimeout or an await fetch, create a new transaction.
Try it in this playground
Run "Keep a folder" and see what prints first 'baris terakhir' prints before any event.
Read req.result before onsuccess The browser throws InvalidStateError.
Make a new drawer with version 2 createObjectStore in onupgradeneeded, the version up.
Use a transaction after setTimeout TransactionInactiveError: the transaction has closed itself.