WorkerGlobalScope: error event
Note: This feature is only available in Web Workers.
The error
event of the WorkerGlobalScope
interface fires when an error occurs in the worker.
Syntax
Use the event name in methods like addEventListener()
, or set an event handler property.
js
addEventListener("error", (event) => {});
onerror = (message, filename, lineno, colno, error) => {};
Event type
A generic Event
.
Example
The following code snippet shows an onerror
handler set inside a worker:
js
self.onerror = () => {
console.log("There is an error inside your worker!");
};
The same snippet, but using addEventListener()
:
js
self.addEventListener("error", () => {
console.log("There is an error inside your worker!");
});
Specifications
Specification |
---|
HTML # handler-workerglobalscope-onerror |
Browser compatibility
Report problems with this compatibility data on GitHubdesktop | mobile | server | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
error event |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
See also
The WorkerGlobalScope
interface it belongs to.