indexedDB setVersion 请求被阻止?
我正在尝试将 indexedDB 与 jax webGL 框架 一起使用,但由于某种原因 setVersion 不起作用。
这是相关的 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"
...
附加到触发的版本请求的唯一处理程序是 onblocked,但我什至不确定请求被阻止意味着什么或为什么会发生这种情况......
为什么版本请求会被阻止?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据 IndexedDB 规范,如果在发出版本更改请求时数据库连接仍处于打开状态,则可能会发送
blocked
事件。请参阅:http://www.w3.org/TR/IndexedDB/#version_change -transaction-steps这是规范中的文本:
3。如果异步运行并且 openDatabases 中的任何连接仍未关闭,请对请求的阻塞事件进行排队。
FWIW:我无法在 Jax 中重现此问题;我知道最好不要说这是不可能的,但目前看起来不太可能是框架中的错误。对应的Jax问题是:https://github.com/sinisterchipmunk/jax/issues/37
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-stepsHere'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
以下是使用 IndexedDB 进行开发时保持数据库连接打开的两种常见方法:
1) 打开多个选项卡。
2)不小心打开数据库两次。
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.