Javascript indexedDB设置版本请求被阻止?

Javascript indexedDB设置版本请求被阻止?,javascript,coffeescript,indexeddb,Javascript,Coffeescript,Indexeddb,我正在尝试将indexedDB与一起使用,但由于某些原因,setVersion无法工作 这是相关的咖啡脚本 if @indexedDB and @objectStore and @key idb_request = indexedDB.open @indexedDB idb_request.onsuccess = (e) => idb = e.target.result if idb.objectStoreNames.contains @objectStore

我正在尝试将indexedDB与一起使用,但由于某些原因,setVersion无法工作

这是相关的咖啡脚本

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,但我甚至不确定阻止请求意味着什么,或者为什么会发生这种情况


为什么会阻止版本请求?

根据IndexedDB规范,如果在发出版本更改请求时数据库连接仍处于打开状态,则可能会发送
阻止事件。见:

以下是规范中的文本:

3。如果异步运行且openDatabases中的任何连接仍未关闭,请为请求排队阻止事件。


FWIW:我无法在Jax中重现这个问题;我不想说这是不可能的,但目前看来这不太可能是框架中的bug。相应的Jax问题是:

在使用IndexedDB开发时,有两种保持数据库连接打开的常用方法:

1) 打开多个选项卡


2) 意外地打开数据库两次

好的,那么在第一种情况下我该怎么做(我该如何强制关闭另一个选项卡上的连接),如果第二种情况可以发生在一个选项卡上,如何避免它?不幸的是,你能做的最好的事情就是监听onblocked事件。这肯定需要编程规则。