WorkerGlobalScope: error event
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Note: This feature is only available inWeb Workers.
Theerror event of theWorkerGlobalScope interface fires when an error occurs in the worker.
In this article
Syntax
Use the event name in methods likeaddEventListener(), or set an event handler property.
js
addEventListener("error", (event) => { })onerror = (message, filename, lineno, colno, error) => { }Event type
A genericEvent.
Example
The following code snippet shows anonerror handler set inside a worker:
js
self.onerror = () => { console.log("There is an error inside your worker!");};The same snippet, but usingaddEventListener():
js
self.addEventListener("error", () => { console.log("There is an error inside your worker!");});Specifications
| Specification |
|---|
| HTML> # handler-workerglobalscope-onerror> |
Browser compatibility
See also
TheWorkerGlobalScope interface it belongs to.