diff --git a/src/main/browser/cdp-ws-proxy.test.ts b/src/main/browser/cdp-ws-proxy.test.ts index 15976e9c729..064895ba54b 100644 --- a/src/main/browser/cdp-ws-proxy.test.ts +++ b/src/main/browser/cdp-ws-proxy.test.ts @@ -647,10 +647,11 @@ describe('CdpWsProxy', () => { }) it('does not register a PDF stream when the client disconnects mid-print', async () => { - let resolvePrint: (buf: Buffer) => void = () => {} + type PrintToPdfData = Awaited> + let resolvePrint: (buf: PrintToPdfData) => void = () => {} mock.webContents.printToPDF.mockImplementationOnce( () => - new Promise((resolve) => { + new Promise((resolve) => { resolvePrint = resolve }) ) diff --git a/src/main/window/createMainWindow.test.ts b/src/main/window/createMainWindow.test.ts index f29b432a19b..e538182d93e 100644 --- a/src/main/window/createMainWindow.test.ts +++ b/src/main/window/createMainWindow.test.ts @@ -2822,6 +2822,7 @@ describe('createMainWindow', () => { invalidate: vi.fn(), setWindowOpenHandler: vi.fn(), send: vi.fn(), + isDestroyed: vi.fn(() => false), id: 1 } const instance = { @@ -2883,6 +2884,20 @@ describe('createMainWindow', () => { expect(webContents.invalidate).not.toHaveBeenCalled() }) + it('does not send the resume event once webContents is destroyed', () => { + const { webContents } = setupResumeWindow() + createMainWindow(null) + const onResume = getPowerResumeListener() + webContents.isDestroyed.mockReturnValue(true) + webContents.send.mockClear() + webContents.invalidate.mockClear() + + onResume() + + expect(webContents.send).not.toHaveBeenCalled() + expect(webContents.invalidate).not.toHaveBeenCalled() + }) + it('removes the powerMonitor resume listener when the window closes', () => { const { windowHandlers } = setupResumeWindow() createMainWindow(null) diff --git a/src/main/window/createMainWindow.ts b/src/main/window/createMainWindow.ts index d868272aafd..c5cd6de20d5 100644 --- a/src/main/window/createMainWindow.ts +++ b/src/main/window/createMainWindow.ts @@ -345,7 +345,7 @@ export function createMainWindow( // run. Relay powerMonitor resume explicitly (supported on mac/win/linux) // and force a repaint so stale compositor surfaces recover too. const onSystemResume = (): void => { - if (mainWindow.isDestroyed()) { + if (mainWindow.isDestroyed() || mainWindow.webContents.isDestroyed?.() === true) { return } forceRepaint(mainWindow)