From cbd9f03d049bc80eaa25c3cab9efc31a85238e5a Mon Sep 17 00:00:00 2001 From: Durgesh kumar prajapati <98798977+Durgesh4993@users.noreply.github.com> Date: Thu, 29 Feb 2024 05:30:00 +0530 Subject: [PATCH] Update service-worker.js --- public/service-worker.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/public/service-worker.js b/public/service-worker.js index 91f973d7178..126ec749de0 100644 --- a/public/service-worker.js +++ b/public/service-worker.js @@ -1,8 +1,19 @@ -self.addEventListener('install', event => self.skipWaiting()); +// Service worker installation event +self.addEventListener('install', event => { + // Skip waiting to activate the service worker immediately + self.skipWaiting(); +}); +// Service worker activation event self.addEventListener("activate", event => { + // Unregister the current service worker self.registration.unregister() - .then(() => self.clients.matchAll()) - .then(clients => clients.forEach(client => client.navigate(client.url))); + .then(() => { + // Retrieve all active clients associated with the service worker + return self.clients.matchAll(); + }) + .then(clients => { + // For each client, navigate to the same URL to reload the page + clients.forEach(client => client.navigate(client.url)); + }); }); -