Description
When a BrowserWindow is closed via window.Close(), the window is destroyed on the Electron side, but the BrowserWindow object remains in the Electron.WindowManager.BrowserWindows collection. This causes errors when subsequently iterating or accessing windows in the collection.
Steps to Reproduce
- Create multiple windows using Electron.WindowManager.CreateWindowAsync()
- Close one or more windows using window.Close()
- Later, iterate over Electron.WindowManager.BrowserWindows and call any method on the windows
Expected Behavior
Closed/destroyed windows should be automatically removed from Electron.WindowManager.BrowserWindows, or there should be a way to detect destroyed windows before accessing them.
Actual Behavior
The collection retains stale BrowserWindow references. Attempting to call methods on these destroyed windows results in:
Uncaught exception: TypeError: Object has been destroyed
at Socket. (....electron\api\browserWindows.js:259:27)
Suggested Fix
Subscribe to Electron's closed event and remove the window from BrowserWindows when it fires