ServiceWorker.onerror

The onerror property of the ServiceWorker interface represents an event handler, that is a function to be called when the error event occurs.

Syntax

myServiceWorker.onerror = function(event) { ... };

Example

The following code snippet gets a handle to the ServiceWorker object via ServiceWorkerRegistration.active and sets up an onerror handler on the resulting object:

// in the page being controlled
if (navigator.serviceWorker) {

  navigator.serviceWorker.register('service-worker.js');

  navigator.serviceWorker.ready.then(registration => {
    registration.active.onerror = (event) => {
      console.log('An error occurred in the service worker!');
    };
  });

}

Specifications

Specification Status Comment
HTML Living Standard
The definition of 'onerror' in that specification.
Living Standard

Browser compatibility

BCD tables only load in the browser