ElectronNET/Electron.NET · error · Error
BrowserWindow with id
Error message
BrowserWindow with id '${id}' was not found. What it means
getWindowById in the Electron host's browserWindows.js looks up a BrowserWindow by numeric id among tracked windows and throws a JS Error when no window matches. Every browserWindow API call (focus, destroy check, visibility, modal, maximized state, etc.) resolves its target through this function, so a stale id fails all of them.
Solutions
- Check the window exists (Electron.WindowManager.BrowserWindow.GetAll()) before operating on it
- Listen for the window 'closed' event and remove the id from your cache
- Confirm you are using the BrowserWindow id (element.id), not a webContents or process id
- Wrap the call so a failed lookup is handled gracefully (e.g. recreate the window)
Example fix
// before
var win = Electron.WindowManager.BrowserWindow.Get(cachedId);
await win.CloseAsync(); // throws if closed
// after
var win = Electron.WindowManager.BrowserWindow.GetAll()
.FirstOrDefault(w => w.Id == cachedId);
if (win != null) await win.CloseAsync(); Defensive patterns
Strategy: type-guard
Validate before calling
const win = electron.BrowserWindow.getAllWindows().find(w => w.id === id);
if (!win) {
console.warn(`Window ${id} not found; skipping call`);
return;
} Type guard
function windowExists(id) {
return electron.BrowserWindow.getAllWindows().some(w => w.id === id);
} Try / catch
try
{
var win = Electron.WindowManager.BrowserWindow.Get(id);
await win.CloseAsync();
}
catch
{
// window already closed — recreate or ignore
logger.LogInformation("Window {Id} not found; it may already be closed", id);
} Prevention
- Subscribe to the window 'closed' event and evict ids from caches
- Resolve windows from GetAll() at call time instead of caching long-lived references
- Never confuse window ids with webContents or process ids
- Guard all window API calls for windows the user can close at any time
When it happens
Trigger: Calling an Electron.NET BrowserWindow API (e.g. Electron.WindowManager.BrowserWindow.Get(id).Close()) with an id that was never created, or whose window has since been closed/destroyed; using an id from a previous app run.
Common situations: Caching window IDs across app restarts; calling APIs on a window after the user closed it; passing a webContents id or other numeric id instead of a window id; race conditions where the window closed before the IPC call arrived.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Unexpected token when reading releaseNotes.
- Invalid value for TitleBarOverlay. Expected boolean or an…
- BrowserWindow with id
AI-assisted analysis of ElectronNET/Electron.NET@87cc6f98b6 (2026-09-14).
Data as JSON: /api/errors/871950ef714fa5ae.
Report an issue: GitHub.
Appendix: source
Thrown at src/ElectronNET.Host/api/browserWindows.js:713
socket.on("browserWindowSetVibrancy", (id, type) => {
getWindowById(id).setVibrancy(type);
});
socket.on("browserWindow-setBrowserView", (id, browserViewId) => {
getWindowById(id).setBrowserView((0, browserView_1.browserViewMediateService)(browserViewId));
});
function getWindowById(id) {
const runtimeWindow = electron_1.BrowserWindow.fromId(id);
if (runtimeWindow) {
return runtimeWindow;
}
synchronizeWindowRegistry();
for (let index = 0; index < windows.length; index++) {
const element = windows[index];
if (tryGetWindowId(element) === id) {
return element;
}
}
throw new Error(`BrowserWindow with id '${id}' was not found.`);
}
function tryGetWindowId(element) {
try {
return element.id;
}
catch {
return null;
}
}
function synchronizeWindowRegistry() {
const runtimeWindows = electron_1.BrowserWindow.getAllWindows();
const runtimeWindowIds = new Set(runtimeWindows.map((entry) => entry.id));
for (let index = windows.length - 1; index >= 0; index--) {
const windowId = tryGetWindowId(windows[index]);
if (windowId === null || !runtimeWindowIds.has(windowId)) {
windows.splice(index, 1);
}
}View on GitHub (pinned to 87cc6f98b6)