WindowManager
Defined in: main/WindowManager.ts:128
Main process window manager. Renderer calls RegisterWindow(id, props) + window.open(url, id), then this class intercepts the new window via setWindowOpenHandler / did-create-window and wraps it.
Security model:
- Iframe enforcement (main-frame-only) is handled by the generated IPC
AppOriginvalidator — it runs before these handlers at the IPC layer. - Parent renderer origin is validated here via
allowedOriginsconfig. - Per-WebContents ownership: a renderer can only mutate windows it created.
UnregisterWindow/UpdateWindow/DestroyWindow/WindowActioncheck that the caller’s WebContents matches the one that registered the window.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new WindowManager(
config?):WindowManager
Defined in: main/WindowManager.ts:139
Parameters
Section titled “Parameters”config?
Section titled “config?”WindowManagerConfig = {}
Returns
Section titled “Returns”WindowManager
Methods
Section titled “Methods”destroy()
Section titled “destroy()”destroy():
void
Defined in: main/WindowManager.ts:695
Returns
Section titled “Returns”void
getAllWindows()
Section titled “getAllWindows()”getAllWindows():
WindowInstance[]
Defined in: main/WindowManager.ts:687
Returns
Section titled “Returns”getWindow()
Section titled “getWindow()”getWindow(
id):WindowInstance|undefined
Defined in: main/WindowManager.ts:683
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”WindowInstance | undefined
getWindowState()
Section titled “getWindowState()”getWindowState(
id):WindowState|null
Defined in: main/WindowManager.ts:691
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”WindowState | null
setupForWindow()
Section titled “setupForWindow()”setupForWindow(
target,options?):void
Defined in: main/WindowManager.ts:237
Attach IPC handling and window.open interception to a WebContents. Works with BrowserWindow, WebContentsView, or any object with a webContents property.
Parameters
Section titled “Parameters”target
Section titled “target”WebContents | BrowserWindow | { webContents: WebContents; }
options?
Section titled “options?”Returns
Section titled “Returns”void
Example
Section titled “Example”// BrowserWindowmanager.setupForWindow(mainWindow);
// WebContentsView (e.g., when the renderer is in a view, not the BrowserWindow itself)manager.setupForWindow(mainView);
// With fallback handler for non-library window.open callsmanager.setupForWindow(mainView, { fallbackWindowOpenHandler: ({ url }) => { if (isExternalURL(url)) { shell.openExternal(url); return { action: "deny" }; } return { action: "allow" }; },});