ServiceWorker: error event

The error event fires whenever an error occurs in the service worker.

Syntax

Use the event name in methods like addEventListener(), or set an event handler property.

addEventListener('error', event => { });

onerror = event => { };

Event type

A generic 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

No specification found

No specification data found for api.ServiceWorker.error_event.
Check for problems with this page or contribute a missing spec_url to mdn/browser-compat-data. Also make sure the specification is included in w3c/browser-specs.

Browser compatibility

No compatibility data found for api.ServiceWorker.error_event.
Check for problems with this page or contribute missing data to mdn/browser-compat-data.