Вот пример того, как я делаю это в одном из моих проектов.
navigator.serviceWorker
.register(swUrl)
.then(registration => {
this.registration = registration;
config.onRegistration();
registration.onupdatefound = () => {
const installingWorker = registration.installing;
if (installingWorker == null) {
return;
}
config.onUpdateFound();
installingWorker.onstatechange = () => {
if (installingWorker.state === 'installed') {
if (navigator.serviceWorker.controller) {
registration.waiting.postMessage('skipWaiting');
config.onUpdateInstalled();
}
} else if (installingWorker.state === 'activated') {
config.onActivated();
}
};
};
})