{"record":{"id":"871950ef714fa5ae","repo":"ElectronNET/Electron.NET","slug":"browserwindow-with-id-id-was-not-found","errorCode":null,"errorMessage":"BrowserWindow with id '${id}' was not found.","messagePattern":"BrowserWindow with id '(.+?)' was not found\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/ElectronNET.Host/api/browserWindows.js","lineNumber":713,"sourceCode":"    socket.on(\"browserWindowSetVibrancy\", (id, type) => {\n        getWindowById(id).setVibrancy(type);\n    });\n    socket.on(\"browserWindow-setBrowserView\", (id, browserViewId) => {\n        getWindowById(id).setBrowserView((0, browserView_1.browserViewMediateService)(browserViewId));\n    });\n    function getWindowById(id) {\n        const runtimeWindow = electron_1.BrowserWindow.fromId(id);\n        if (runtimeWindow) {\n            return runtimeWindow;\n        }\n        synchronizeWindowRegistry();\n        for (let index = 0; index < windows.length; index++) {\n            const element = windows[index];\n            if (tryGetWindowId(element) === id) {\n                return element;\n            }\n        }\n        throw new Error(`BrowserWindow with id '${id}' was not found.`);\n    }\n    function tryGetWindowId(element) {\n        try {\n            return element.id;\n        }\n        catch {\n            return null;\n        }\n    }\n    function synchronizeWindowRegistry() {\n        const runtimeWindows = electron_1.BrowserWindow.getAllWindows();\n        const runtimeWindowIds = new Set(runtimeWindows.map((entry) => entry.id));\n        for (let index = windows.length - 1; index >= 0; index--) {\n            const windowId = tryGetWindowId(windows[index]);\n            if (windowId === null || !runtimeWindowIds.has(windowId)) {\n                windows.splice(index, 1);\n            }\n        }","sourceCodeStart":695,"sourceCodeEnd":731,"githubUrl":"https://github.com/ElectronNET/Electron.NET/blob/87cc6f98b6a9c5968d7846c0e775ea713bd0d7b2/src/ElectronNET.Host/api/browserWindows.js#L695-L731","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)"],"exampleFix":"// before\nvar win = Electron.WindowManager.BrowserWindow.Get(cachedId);\nawait win.CloseAsync(); // throws if closed\n// after\nvar win = Electron.WindowManager.BrowserWindow.GetAll()\n    .FirstOrDefault(w => w.Id == cachedId);\nif (win != null) await win.CloseAsync();","handlingStrategy":"type-guard","validationCode":"const win = electron.BrowserWindow.getAllWindows().find(w => w.id === id);\nif (!win) {\n    console.warn(`Window ${id} not found; skipping call`);\n    return;\n}","typeGuard":"function windowExists(id) {\n    return electron.BrowserWindow.getAllWindows().some(w => w.id === id);\n}","tryCatchPattern":"try\n{\n    var win = Electron.WindowManager.BrowserWindow.Get(id);\n    await win.CloseAsync();\n}\ncatch\n{\n    // window already closed — recreate or ignore\n    logger.LogInformation(\"Window {Id} not found; it may already be closed\", id);\n}","preventionTips":["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"],"tags":["electron","browserwindow","not-found","javascript"],"backgroundTag":"resource-not-found","analyzedSha":"87cc6f98b6a9c5968d7846c0e775ea713bd0d7b2","analyzedAt":"2026-09-14T03:09:47.608Z","contentChangedAt":"2026-09-14T03:09:47.608Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}