From 8396bdeb48c9e64f450ff65b97c974fb9077cf3c Mon Sep 17 00:00:00 2001 From: liangxu Date: Fri, 8 May 2026 22:30:43 +0800 Subject: [PATCH] fix(desktop): disable main/preload minification to keep page.evaluate stable Playwright serializes the function passed to page.evaluate via .toString() and runs it in the browser context. With main-process minify on, esbuild renames inlined helpers (e.g. __name) and closure references to two-letter identifiers like FK/p/ed; their definitions stay at module scope on the Node side, so the browser eval throws ReferenceError. Mac dev builds were unaffected because dev mode doesn't minify; only packaged Windows builds hit this. Main process bundle size is irrelevant (loaded once on startup) so turning minify off is the cheapest correct fix. Co-Authored-By: Claude Opus 4.7 (1M context) --- apps/desktop-client/electron.vite.config.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/apps/desktop-client/electron.vite.config.ts b/apps/desktop-client/electron.vite.config.ts index de9b7f9..c4fbfc3 100644 --- a/apps/desktop-client/electron.vite.config.ts +++ b/apps/desktop-client/electron.vite.config.ts @@ -29,6 +29,12 @@ export default defineConfig({ plugins: [externalizeDepsPlugin({ exclude: workspacePackages })], build: { sourcemap: 'hidden', + // Disable minification for the main process: the bundle is only loaded + // once on app startup so size is irrelevant, and minified short names + // break Playwright `page.evaluate` because the function is serialized + // via `.toString()` and helper identifiers (e.g. `__name` renamed to + // `FK`) become undefined in the browser context. + minify: false, rollupOptions: { input: { bootstrap: resolve(rootDir, 'src/main/bootstrap.ts'), @@ -51,6 +57,7 @@ export default defineConfig({ plugins: [externalizeDepsPlugin({ exclude: workspacePackages })], build: { sourcemap: 'hidden', + minify: false, rollupOptions: { input: { bridge: resolve(rootDir, 'src/preload/bridge.ts'),