Worker: messageerror event

这篇翻译不完整。请帮忙从英语翻译这篇文章

Worker 对象接收到一条无法被反序列化的消息时, messageerror 事件将在该对象上被触发。

是否冒泡
是否可取消
接口 MessageEvent
对应事件处理属性 onmessageerror

例子

创建一个 worker ,使用 addEventListener() 监听 message 和 messageerror 事件:

// inside main.js

const worker = new Worker("static/scripts/worker.js");

worker.addEventListener("message", (event) => {
    console.error(`Received message from worker: ${event}`);
});

worker.addEventListener("messageerror", (event) => {
    console.error(`Error receiving message from worker: ${event}`);
});

同样,可以使用 onmessageerror 事件处理属性监听事件:

// inside main.js

const worker = new Worker("static/scripts/worker.js");

worker.onmessage = (event) => {
    console.error(`Received message from worker: ${event}`);
};

worker.onmessageerror = (event) => {
    console.error(`Error receiving message from worker: ${event}`);
};

规范

Specification Status
HTML Living Standard Living Standard

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
messageerror eventChrome Full support 60Edge Full support 18Firefox Full support 57IE ? Opera Full support 47Safari ? WebView Android Full support 60Chrome Android Full support 60Firefox Android Full support 57Opera Android Full support 47Safari iOS ? Samsung Internet Android No support No

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown

另请参阅

文档标签和贡献者

此页面的贡献者: LittleIQ
最后编辑者: LittleIQ,