Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

web: fix issue with service worker not getting registered

Abdullah Atta0c16bfb5ff10
diff --git a/apps/web/src/service-worker-registration.ts b/apps/web/src/service-worker-registration.ts
index a454e31f6..b3a17d484 100644
--- a/apps/web/src/service-worker-registration.ts
+++ b/apps/web/src/service-worker-registration.ts
@@ -56,26 +56,23 @@ export function register(config: ServiceWorkerRegistrationConfig) {
return;
}
- window.addEventListener("load", () => {
- const swUrl = `${PUBLIC_URL}/service-worker.js`;
-
- if (isLocalhost) {
- // This is running on localhost. Let's check if a service worker still exists or not.
- checkValidServiceWorker(swUrl, config);
-
- // Add some additional logging to localhost, pointing developers to the
- // service worker/PWA documentation.
- navigator.serviceWorker.ready.then(() => {
- console.log(
- "This web app is being served cache-first by a service " +
- "worker. To learn more, visit https://cra.link/PWA"
- );
- });
- } else {
- // Is not localhost. Just register service worker
- registerValidSW(swUrl, config);
- }
- });
+ const swUrl = `${PUBLIC_URL}/service-worker.js`;
+ if (isLocalhost) {
+ // This is running on localhost. Let's check if a service worker still exists or not.
+ checkValidServiceWorker(swUrl, config);
+
+ // Add some additional logging to localhost, pointing developers to the
+ // service worker/PWA documentation.
+ navigator.serviceWorker.ready.then(() => {
+ console.log(
+ "This web app is being served cache-first by a service " +
+ "worker. To learn more, visit https://cra.link/PWA"
+ );
+ });
+ } else {
+ // Is not localhost. Just register service worker
+ registerValidSW(swUrl, config);
+ }
}
}