From fa15f7da8589b00cb8dc52684e3409251098de88 Mon Sep 17 00:00:00 2001 From: Matthew Raymer Date: Fri, 14 Feb 2025 03:31:03 +0000 Subject: [PATCH] fix: remove navigator.serviceWorker redefinition in Vite config The previous configuration attempted to redefine the read-only navigator.serviceWorker property, which caused runtime errors. Instead, we now handle service worker availability through the transform plugin, which safely removes service worker code in Electron and PyWebView builds. This fixes the error: "Cannot set property serviceWorker of # which has only a getter" Technical changes: - Removed navigator.serviceWorker from define section - Rely on existing transform plugin to handle service worker code removal - Maintains existing PWA functionality for web builds while properly disabling it for desktop builds --- vite.config.mjs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vite.config.mjs b/vite.config.mjs index e802c1e..56a2ef1 100644 --- a/vite.config.mjs +++ b/vite.config.mjs @@ -60,9 +60,8 @@ export default defineConfig(({ mode }) => { }, define: { 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV), - 'process.env.VITE_PWA_ENABLED': JSON.stringify(!isElectron), + 'process.env.VITE_PWA_ENABLED': JSON.stringify(!(isElectron || isPyWebView)), __dirname: isElectron ? JSON.stringify(process.cwd()) : '""', - 'navigator.serviceWorker': isElectron ? 'undefined' : 'navigator.serviceWorker' }, plugins: [ vue(),