Provides a means to registering a service worker in the browser and communicating with it via postMessage events. https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API/

postMessage events are currently not supported in all browsers. See: https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API

At the minmum this class will register the service worker and listen and attempt to dispatch messages on state change and record analytics events based on the service worker lifecycle.

Constructors

Accessors

Methods

  • Register the service-worker.js file in the browser Make sure the service-worker.js is part of the build for example with Angular, modify the angular-cli.json file and add to "assets" array "service-worker.js"

    Parameters

    Returns Promise<unknown>

    • resolve(ServiceWorkerRegistration)
      • reject(Error)
  • Send a message to the service worker. The service worker needs to implement `self.addEventListener('message') to handle the message. This currently does not work in Safari or IE.

    Parameters

    Returns void