web api event
WorkerGlobalScope: error event
Available in 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.
addEventListener("error", (event) => { })
onerror = (message, filename, lineno, colno, error) => { }
[!NOTE] For historical reasons,
onerroronWindowandWorkerGlobalScopeobjects is the only event handler property that receives more than one argument.For more details about this, see the page for the
errorevent onWindowobjects.
Event type
A generic Event.
Example
The following code snippet shows an onerror handler set inside a worker:
self.onerror = () => {
console.log("There is an error inside your worker!");
};
The same snippet, but using addEventListener():
self.addEventListener("error", () => {
console.log("There is an error inside your worker!");
});
Specifications
SpecificationsStandards references are available on the canonical MDN page.
Browser compatibility
Browser compatibilityCompatibility data is available on the canonical MDN page.
See also
The WorkerGlobalScope interface it belongs to.