From 77c698e00bebcb5eea16f0f6fec67a9a3d866e1b Mon Sep 17 00:00:00 2001 From: sudacode Date: Fri, 27 Feb 2026 00:39:59 -0800 Subject: [PATCH] fix(overlay): tolerate minimal webContents in bridge send path --- src/core/services/overlay-bridge.ts | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/core/services/overlay-bridge.ts b/src/core/services/overlay-bridge.ts index 99642da..d4a0f64 100644 --- a/src/core/services/overlay-bridge.ts +++ b/src/core/services/overlay-bridge.ts @@ -13,6 +13,11 @@ export function sendToVisibleOverlayRuntime(options: { }): boolean { if (!options.mainWindow || options.mainWindow.isDestroyed()) return false; const wasVisible = options.visibleOverlayVisible; + const webContents = options.mainWindow.webContents as Electron.WebContents & { + isLoading?: () => boolean; + getURL?: () => string; + once?: (event: 'did-finish-load', listener: () => void) => void; + }; if (!options.visibleOverlayVisible) { options.setVisibleOverlayVisible(true); } @@ -21,22 +26,27 @@ export function sendToVisibleOverlayRuntime(options: { } const sendNow = (): void => { if (options.payload === undefined) { - options.mainWindow!.webContents.send(options.channel); + webContents.send(options.channel); } else { - options.mainWindow!.webContents.send(options.channel, options.payload); + webContents.send(options.channel, options.payload); } }; - const currentURL = options.mainWindow.webContents.getURL(); + const isLoading = typeof webContents.isLoading === 'function' ? webContents.isLoading() : false; + const currentURL = typeof webContents.getURL === 'function' ? webContents.getURL() : ''; const isReady = - !options.mainWindow.webContents.isLoading() && + !isLoading && currentURL !== '' && currentURL !== 'about:blank'; if (!isReady) { - options.mainWindow.webContents.once('did-finish-load', () => { + if (typeof webContents.once !== 'function') { + sendNow(); + return true; + } + webContents.once('did-finish-load', () => { if (!options.mainWindow || options.mainWindow.isDestroyed()) return; - if (!options.mainWindow.webContents.isLoading()) { + if (typeof webContents.isLoading !== 'function' || !webContents.isLoading()) { sendNow(); } });