From 0fe51c627e1e4a4a418e5cd742740a90dcaddedf Mon Sep 17 00:00:00 2001 From: therockerline Date: Wed, 29 Jan 2025 10:59:11 +0100 Subject: [PATCH] fix: add the try catch block on UPDATE_SHARED_STATE to catch the error when a page has been destroyed before electron can share the updated data with it --- src/main/lib/ipcEvents.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/lib/ipcEvents.ts b/src/main/lib/ipcEvents.ts index d8f9f5d..2183de5 100644 --- a/src/main/lib/ipcEvents.ts +++ b/src/main/lib/ipcEvents.ts @@ -86,8 +86,13 @@ export function registerIpcEvents() { const windows = BrowserWindow.getAllWindows(); store.updateStore(newState, `${page}[${selector}]`) windows.forEach(win => { - if (page !== win.webContents.getTitle()) { - win.webContents.send(IPC_EVENTS.SHARED_STATE_UPDATED, newState, page); + const targetPage = win.webContents.getTitle() + try { + if (page !== targetPage) { + win.webContents.send(IPC_EVENTS.SHARED_STATE_UPDATED, newState, page); + } + } catch (e) { + Log.error(`Data origin: ${page}, target: ${targetPage}`, e) } }); });