"由于页面导航而导致尚未完成的IndexedDB事务已中止"

时间:2015-03-24 20:32:47

标签: javascript firefox indexeddb

我正在使用IndexedDB来存储一些数据。它似乎有效,但如果我刷新页面,我会在Firefox(36.0.4)的浏览器控制台中看到An IndexedDB transaction that was not yet complete has been aborted due to page navigation.。我正在使用这个(本地)文件来测试:

<html>
  <head><meta charset="UTF-8"></head>
  <body>
    <script>
var request = window.indexedDB.open("test_db", 2);
request.onupgradeneeded = function (event) {
  request.result.createObjectStore("test_store");
};

request.onsuccess = function (event) {
  var db = request.result;
  var transaction = db.transaction(["test_store"], "readwrite");
  var put = transaction.objectStore("test_store").put("key", "value");
  transaction.oncomplete = function (event) {
    console.log("Transaction complete");
  };
};
    </script>
  </body>
</html>

如果我执行多个事务,则会出现多个错误。如果我有一个执行事务的onclick处理程序并且我多次单击它,则刷新会为我过去的每笔交易打印一个错误。

所有这些让我觉得我的交易没有被清理干净。完成交易需要做什么?

正在调用我的oncomplete处理程序。刷新几次,浏览器控制台如下所示:

"Transaction complete" test.html:16:1
An IndexedDB transaction that was not yet complete has been aborted due to page navigation. test.html:13:0
"Transaction complete" test.html:16:1
An IndexedDB transaction that was not yet complete has been aborted due to page navigation. test.html:13:0
"Transaction complete" test.html:16:1

测试页面(Ctrl-Shift-J打开控制台,然后按Ctrl-R刷新显示错误):

http://test.roscidus.com/static/idb.html

1 个答案:

答案 0 :(得分:1)

错误was a bug in Firefox,现在它已经修复:

  

状态:已解决修复

此修复程序在Firefox 41上完成,which was released on Sep 22th 2015

  

跟踪标志:status-firefox41:fixed