如何让错误事件在 indexedDB.deleteDatabase 中触发?

How do I get the error event to fire in indexedDB.deleteDatabase?

The documentation 说:

If an error occurs while the database is being deleted, then an error event is fired on the request object that is returned from this method.

问:如何调用错误以便查看事件中的内容? 我尝试删除 null 和 undefined,并且没有使用任何参数,但我无法触发错误回调。

deleteDatabase 引发错误的唯一原因是浏览器中存在内部错误,例如保存数据库的存储设备已断开连接。

无法从脚本中触发此案例。巧合的是,我在做一些规范工作时注意到了这一点,并提交了一个 spec issue, and added a clause to the spec 来解释它:"If this fails for any reason..."

活动的详细信息可以在steps for deleteDatabase中找到:

If result is an error set the error of request to result and dispatch an event at request. The event must use the Event interface and set the type attribute to "error".

请注意,有关 bubbles/cancelable 的后续详细信息是 open spec issue 本身。

copy/pasted 来自您提供的原始 link。并添加了 onerror

var DBDeleteRequest = window.indexedDB.deleteDatabase("toDoList");

DBDeleteRequest.onerror = function(event) {
  console.log("Error deleting database.");
};

DBDeleteRequest.onsuccess = function(event) {
  console.log("Database deleted successfully");

  console.log(request.result); // should be null
};

DBDeleteRequest.onerror = function(event) {
  console.error("error in deleting database");
//console.error = read coloring in console.  vs coloring with .log of console
  console.log(event);
}

以下纯属猜测

是否存在某种疯狂的 "read/write/delete" 位置权限,因为 indexeddb 文件存储在硬盘驱动器上,可能导致 "onerror" 或者硬盘驱动器例如是一个 USB 驱动器并且被拔掉了?

交易仍在进行中并挂在一个循环或其他东西中并且没有正确结束并且从未发生 "oncomplete" 事件。完成问题。管理员在这里按下 "stinking delete button" 但停止删除数据库。可以很容易地看到 "non computer person" 正在做某事,并尝试删除某些东西,而其他选项卡中正在发生其他事情等等。