Skip to content

fix(window): guard close handler against destroyed BrowserWindow #1782

@kaizhou-lab

Description

@kaizhou-lab

Description

When close-to-tray is enabled, the main window's close event handler calls mainWindow.hide(). If the BrowserWindow has already been destroyed (e.g. triggered via windowControlsBridge.close()), this throws TypeError: Object has been destroyed.

Context

Sentry ELECTRON-ET — 7 occurrences on v1.8.32, fatal level error. The race condition occurs when the close event fires on a window that has been destroyed between the close() call and the event handler execution.

Fix

Add mainWindow.isDestroyed() guard at the top of the close handler to bail out early.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions