Skip to content

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 AppOrigin validator — it runs before these handlers at the IPC layer.
  • Parent renderer origin is validated here via allowedOrigins config.
  • Per-WebContents ownership: a renderer can only mutate windows it created. UnregisterWindow/UpdateWindow/DestroyWindow/WindowAction check that the caller’s WebContents matches the one that registered the window.

new WindowManager(config?): WindowManager

Defined in: main/WindowManager.ts:139

WindowManagerConfig = {}

WindowManager

destroy(): void

Defined in: main/WindowManager.ts:695

void


getAllWindows(): WindowInstance[]

Defined in: main/WindowManager.ts:687

WindowInstance[]


getWindow(id): WindowInstance | undefined

Defined in: main/WindowManager.ts:683

string

WindowInstance | undefined


getWindowState(id): WindowState | null

Defined in: main/WindowManager.ts:691

string

WindowState | null


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.

WebContents | BrowserWindow | { webContents: WebContents; }

SetupOptions

void

// BrowserWindow
manager.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 calls
manager.setupForWindow(mainView, {
fallbackWindowOpenHandler: ({ url }) => {
if (isExternalURL(url)) { shell.openExternal(url); return { action: "deny" }; }
return { action: "allow" };
},
});