Reputation: 3077
I'm trying to use indexedDB with jax webGL framework but for some reason setVersion isn't working.
Here's the relevant coffeescript
if @indexedDB and @objectStore and @key
idb_request = indexedDB.open @indexedDB
idb_request.onsuccess = (e) =>
idb = e.target.result
if idb.objectStoreNames.contains @objectStore
store = idb.transaction([@objectStore], IDBTransaction.READ_WRITE).objectStore(@objectStore)
else
console.log idb.version # => ""
version_request = idb.setVersion(0.1)
version_request.onblocked = (e) -> console.log e #=> this one fires
version_request.onerror = (e) -> console.log e
version_request.onsuccess = (e) -> console.log e
version_request.onfailure = (e) -> console.log e
idb_request.onerror = (e) -> console.log "ERROR: Unable to open indexedDB"
...
The only handler attached to the version request that fires is onblocked, But i'm not even sure what it means for the request to be blocked or why this would happen...
Why would a version request be blocked?
Upvotes: 3
Views: 1247
Reputation: 29248
Here are two common ways to leave a database connection open when developing with IndexedDB:
1) Have multiple tabs open.
2) Accidentally open the database twice.
Upvotes: 1
Reputation: 2023
According to the IndexedDB spec it's possible a blocked
event might be sent if a database connection is still open while a version change request is made. See: http://www.w3.org/TR/IndexedDB/#version_change-transaction-steps
Here's the text from the spec:
3. If running asynchronously and any of the connections in openDatabases are still not closed, queue up a blocked event for the request.
FWIW: I couldn't reproduce this issue in Jax; I know better than to say it isn't possible, but it's looking unlikely to be a bug in the framework at this time. The corresponding Jax issue is: https://github.com/sinisterchipmunk/jax/issues/37
Upvotes: 1