From 85adb39d31eb2f8c2aea0151af343e6bfef20f39 Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Mon, 27 Feb 2023 10:46:00 -0800 Subject: [PATCH] Ignore more ERR_FAILED instances --- app/main.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/main.ts b/app/main.ts index 30574193c..346d346f4 100644 --- a/app/main.ts +++ b/app/main.ts @@ -670,10 +670,20 @@ async function getTitleBarOverlay(): Promise { } async function safeLoadURL(window: BrowserWindow, url: string): Promise { + let wasDestroyed = false; + const onDestroyed = () => { + wasDestroyed = true; + }; + + window.webContents.on('did-stop-loading', onDestroyed); + window.webContents.on('destroyed', onDestroyed); try { await window.loadURL(url); } catch (error) { - if (windowState.readyForShutdown() && error?.code === 'ERR_FAILED') { + if ( + (wasDestroyed || windowState.readyForShutdown()) && + error?.code === 'ERR_FAILED' + ) { getLogger().warn( 'safeLoadURL: ignoring ERR_FAILED because we are shutting down', error @@ -681,6 +691,9 @@ async function safeLoadURL(window: BrowserWindow, url: string): Promise { return; } throw error; + } finally { + window.webContents.removeListener('did-stop-loading', onDestroyed); + window.webContents.removeListener('destroyed', onDestroyed); } }