diff --git a/app/index.tsx b/app/index.tsx index 3f5ff9f4aa..a12a05dca6 100644 --- a/app/index.tsx +++ b/app/index.tsx @@ -21,7 +21,6 @@ import { initI18n } from "~/utils/i18n"; import Desktop from "./components/DesktopEventHandler"; import LazyPolyfill from "./components/LazyPolyfills"; import Routes from "./routes"; -import Logger from "./utils/Logger"; import history from "./utils/history"; import { initSentry } from "./utils/sentry"; @@ -38,33 +37,6 @@ if (env.SENTRY_DSN) { initSentry(history); } -if ("serviceWorker" in window.navigator) { - window.addEventListener("load", () => { - // see: https://bugs.chromium.org/p/chromium/issues/detail?id=1097616 - // In some rare (<0.1% of cases) this call can return `undefined` - const maybePromise = window.navigator.serviceWorker.register( - "/static/service-worker.js", - { - scope: "/", - } - ); - - if (maybePromise?.then) { - maybePromise - .then((registration) => { - Logger.debug("lifecycle", "SW registered: ", registration); - }) - .catch((registrationError) => { - Logger.debug( - "lifecycle", - "SW registration failed: ", - registrationError - ); - }); - } - }); -} - // Make sure to return the specific export containing the feature bundle. const loadFeatures = () => import("./utils/motion").then((res) => res.default); diff --git a/app/sw/registerSW.ts b/app/sw/registerSW.ts index a4ed9994cc..215613a2c7 100644 --- a/app/sw/registerSW.ts +++ b/app/sw/registerSW.ts @@ -1 +1,25 @@ -export default console.log("Hello, I’m there to register the service worker."); +import Logger from "~/utils/Logger"; + +if ("serviceWorker" in navigator) { + window.addEventListener("load", () => { + // see: https://bugs.chromium.org/p/chromium/issues/detail?id=1097616 + // In some rare (<0.1% of cases) this call can return `undefined` + const maybePromise = navigator.serviceWorker.register("/sw.js", { + scope: "/", + }); + + if (maybePromise?.then) { + maybePromise + .then((registration) => { + Logger.debug("lifecycle", "SW registered: ", registration); + }) + .catch((registrationError) => { + Logger.debug( + "lifecycle", + "SW registration failed: ", + registrationError + ); + }); + } + }); +}