Ignore more ERR_FAILED instances

This commit is contained in:
Fedor Indutny 2023-02-27 10:46:00 -08:00 committed by GitHub
parent 0e655ceeed
commit 85adb39d31
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -670,10 +670,20 @@ async function getTitleBarOverlay(): Promise<TitleBarOverlayOptions | false> {
}
async function safeLoadURL(window: BrowserWindow, url: string): Promise<void> {
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<void> {
return;
}
throw error;
} finally {
window.webContents.removeListener('did-stop-loading', onDestroyed);
window.webContents.removeListener('destroyed', onDestroyed);
}
}