AbstractWorker.onerror

概述

AbstractWorker接口的onerror特性是一个事件句柄,在 Workererror (en-US)事件触发并冒泡时执行。

语法

myWorker.onerror = function() { ... };

示例

下面的代码片段展示了通过 Worker() 创建 Worker 对象的过程, 以及设置onerror回调函数:

var myWorker = new Worker("worker.js");

myWorker.onerror = function() {
  console.log('There is an error with your worker!');
}

规范

Specification Status Comment
HTML Living Standard
AbstractWorker.onerror
Living Standard No change from Unknown.
Unknown
AbstractWorker.onerror
Unknown Initial definition.

浏览器兼容性

BCD tables only load in the browser

早期浏览器会抛出 SecurityError,在规范变更后,则是  error (en-US) 事件。具体见 Loading cross-origin worker now fires error event instead of throwing; worker in sandboxed iframe no longer allowed.

 

另请参阅