Reacting to Incoming Events in a Service Worker

Learn how to install and activate a service worker.

As service workers run in the background, their purpose is to handle events. Therefore, we attach event listeners to the service worker to react to these events.

The self keyword is used to refer to the service worker. To add an event listener, we use the addEventListener() method on this self object.

Note: Service workers don’t have DOM access, so we can’t listen to DOM events like click.

Listening to the install event

Get hands-on with 1200+ tech skills courses.