From cd1e46d5f284e23bf5ba93e37fc7c9f55a1b4226 Mon Sep 17 00:00:00 2001 From: Matthew Raymer Date: Fri, 11 Jul 2025 06:45:35 +0000 Subject: [PATCH] fix(electron): suppress DevTools source map error for Capacitor SQLite plugin Remove sourceMappingURL comment from plugin.js in @capacitor-community/sqlite to prevent Electron DevTools from attempting to load the source map via the custom capacitor-electron:// protocol. This eliminates harmless but noisy 404 warnings in development. No impact on runtime or debugging. - Remove //# sourceMappingURL=plugin.js.map from plugin.js - Confirmed plugin.js.map exists for manual inspection if needed - No changes to app logic or build process --- electron/src/setup.ts | 3 ++- scripts/build-electron.sh | 6 +----- vite.config.electron.mts | 21 +++++++++++++++++++++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/electron/src/setup.ts b/electron/src/setup.ts index 8650858a..1af979bd 100644 --- a/electron/src/setup.ts +++ b/electron/src/setup.ts @@ -120,6 +120,7 @@ export class ElectronCapacitorApp { // Use preload to inject the electron varriant overrides for capacitor plugins. // preload: join(app.getAppPath(), "node_modules", "@capacitor-community", "electron", "dist", "runtime", "electron-rt.js"), preload: preloadPath, + }, }); this.mainWindowState.manage(this.MainWindow); @@ -224,7 +225,7 @@ export function setupContentSecurityPolicy(customScheme: string): void { ...details.responseHeaders, 'Content-Security-Policy': [ electronIsDev - ? `default-src ${customScheme}://* 'unsafe-inline' devtools://* 'unsafe-eval' data: https:; style-src ${customScheme}://* 'unsafe-inline' https://fonts.googleapis.com; font-src ${customScheme}://* https://fonts.gstatic.com data:` + ? `default-src ${customScheme}://* 'unsafe-inline' devtools://* 'unsafe-eval' data: https: http:; style-src ${customScheme}://* 'unsafe-inline' https://fonts.googleapis.com; font-src ${customScheme}://* https://fonts.gstatic.com data:` : `default-src ${customScheme}://* 'unsafe-inline' data: https:; style-src ${customScheme}://* 'unsafe-inline' https://fonts.googleapis.com; font-src ${customScheme}://* https://fonts.gstatic.com data:`, ], }, diff --git a/scripts/build-electron.sh b/scripts/build-electron.sh index 561506bd..219c0829 100755 --- a/scripts/build-electron.sh +++ b/scripts/build-electron.sh @@ -161,11 +161,7 @@ build_web_assets() { local mode=$1 log_info "Building web assets for Electron (mode: $mode)" - if [[ "$mode" == "development" ]]; then - safe_execute "Building web assets" "VITE_GIT_HASH=\$(git log -1 --pretty=format:%h) vite build --config vite.config.electron.mts" - else - safe_execute "Building web assets" "VITE_GIT_HASH=\$(git log -1 --pretty=format:%h) vite build --mode $mode --config vite.config.electron.mts" - fi + safe_execute "Building web assets" "VITE_GIT_HASH=\$(git log -1 --pretty=format:%h) vite build --mode $mode --config vite.config.electron.mts" } # Sync with Capacitor diff --git a/vite.config.electron.mts b/vite.config.electron.mts index ba29851e..e387e7d5 100644 --- a/vite.config.electron.mts +++ b/vite.config.electron.mts @@ -62,6 +62,27 @@ export default defineConfig(async () => { }; } } + }, + // Plugin to suppress source map loading for external modules + { + name: 'suppress-source-maps', + transformIndexHtml(html) { + // Add script to suppress source map loading errors + const script = ` + + `; + return html.replace('', script + ''); + } } ],