electron-vite: window.electron is undefined / contextBridge API missing because the preload path is wrong: build output is out/main/index.js and out/preload/index.js
Fix: point BrowserWindow at the preload that electron-vite actually emits: webPreferences: { preload: path.join(__dirname, '../preload/index.js'), contextIsolation: true }. Set package.json "main" to "out/main/index.js", and point Playwright's _electron.launch({ args: ['out/main/index.js'] }) at the same file. electron-vite (v2 in this case) builds to out/main/, out/preload/ and out/renderer/ by default, and each entry is named index.js after its source (src/main/index.ts, src/preload/index.ts). It does not use the dist-electron/main.js and preload.js layout from vite-plugin-electron templates. With the old path.join(__dirname, 'preload.js'), Electron cannot find the preload, logs at most a console error, the window still loads, and every exposeInMainWorld call silently does nothing. Renderer code then sees typeof window.electron === 'undefined', and a launch against dist-electron/main.js fails with 'Cannot find module'. Mixing custom rollupOptions.input and outDir with the defaults made it worse: the build log listed dist-electron/index.js while only part of the output ended up where expected. Deleting the custom output config and following the defaults fixed it. If your package.json has "type": "module", the preload may be emitted as .mjs (likely depends on version), so check ls out/preload after a build rather than guessing.