new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Electron · API · all subjects

app/windows

78 notes in this subject, read out of this brain and free to use. This is page 2 of 2.

window.open() features string parsing

The features parameter is a comma-separated key-value list following the standard browser format. Electron parses a subset of presentational BrowserWindowConstructorOptions from this list, including: width, height, x, y, show, frame, title, and backgroundColor. Options that cause the main process to access the filesystem or are otherwise privileged (such as icon) are ignored by the renderer.

WebPreferences options in window.open() features string

A subset of WebPreferences can be set directly, unnested, from the features string: zoomFactor, nodeIntegration, javascript, contextIsolation, and webviewTag.

window.open() security inheritance rules

Node integration will always be disabled in the opened window if it is disabled on the parent window. Context isolation will always be enabled in the opened window if it is enabled on the parent window. JavaScript will always be disabled in the opened window if it is disabled on the parent window.

window.open() process behavior for same-site content

For same-site content, the new window is created within the same process, enabling the parent to access the child window directly. This allows the parent to render to the sub-window directly, similar to rendering a div in the parent, matching browser behavior.

window.open() process isolation when sandbox differs

Process-level webPreferences such as sandbox and nodeIntegration are baked into a renderer process when it launches. If a child window's sandbox state differs from the opener's process, the child cannot share it and is created in its own process with no opener relationship. In this case, window.open() returns null in the opener and window.opener is null in the child.

window.open() sandbox defaults to true

Child windows default to sandboxed. A window.open() from an unsandboxed opener (for example one with nodeIntegration: true) is isolated by default. To keep a child in the opener's process, explicitly set sandbox: false in the webPreferences returned from webContents.setWindowOpenHandler().

webContents.setWindowOpenHandler() return object structure

The setWindowOpenHandler() handler should return an object. Returning { action: 'deny' } cancels the window creation. Returning { action: 'allow', overrideBrowserWindowOptions: { ... } } allows the window and sets the BrowserWindowConstructorOptions. The outlivesOpener property can also be passed: { action: 'allow', outlivesOpener: true, overrideBrowserWindowOptions: { ... } }. If outlivesOpener is set to true, the newly created window will not close when the opener window closes. The default value is false.

BrowserWindow constructor options precedence for window.open()

BrowserWindow constructor options are set by, in increasing precedence order: parsed options from the features string from window.open(), security-related webPreferences inherited from the parent, and options given by webContents.setWindowOpenHandler(). The webContents.setWindowOpenHandler() has final say and full privilege because it is invoked in the main process.

window.open() with about:blank inherits parent WebPreferences

When opening about:blank, the child window's WebPreferences will be copied from the parent window, and there is no way to override it because Chromium skips browser side navigation in this case.

window.open() examples using setWindowOpenHandler

Example showing how to use setWindowOpenHandler to customize window.open() creation. Only windows with the about:blank url will be created; all other urls will be blocked. The handler returns { action: 'allow', overrideBrowserWindowOptions: { frame: false, fullscreenable: false, backgroundColor: 'black', webPreferences: { preload: 'my-child-window-preload-script.js' } } } for allowed windows. Code: mainWindow.webContents.setWindowOpenHandler(({ url }) => { if (url === 'about:blank') { return { action: 'allow', overrideBrowserWindowOptions: { frame: false, fullscreenable: false, backgroundColor: 'black', webPreferences: { preload: 'my-child-window-preload-script.js' } } } } return { action: 'deny' } })

window.open() renderer process example

Example showing how to open a window from the renderer process and manipulate its document. Code: const childWindow = window.open('', 'modal'); childWindow.document.write('<h1>Hello</h1>')

window.open() features string example

Example of using window.open() with a features string: window.open('https://github.com', '_blank', 'top=500,left=200,frame=false,nodeIntegration=no')

Ways to create windows from renderer

Windows can be created from the renderer in two ways: clicking on links or submitting forms adorned with target=_blank, or JavaScript calling window.open().

frameName follows native Window.open specification

The frameName parameter follows the specification of target located in the native documentation at https://developer.mozilla.org/en-US/docs/Web/API/Window/open#parameters.

BrowserWindow can only be created after ready event

BrowserWindows can only be created after the app module's 'ready' event is fired. Use app.whenReady().then() or app.on('ready') to wait for this event before calling the window creation code.

Window all closed event on Windows and Linux

On Windows and Linux, closing all windows will generally quit an application entirely. Listen for the app module's 'window-all-closed' event and call app.quit() to exit the app if the user is not on macOS. Example: app.on('window-all-closed', () => { if (process.platform !== 'darwin') app.quit() })

Activate event for macOS window behavior

macOS apps generally continue running even without any windows open. Listen for the app module's 'activate' event and call createWindow() if no BrowserWindows are open. Only listen for activate events inside the whenReady() callback after the app is initialized.

Get all open BrowserWindow instances

Call BrowserWindow.getAllWindows() to get an array of all open BrowserWindow instances. This can be used to check if any windows are open, for example: if (BrowserWindow.getAllWindows().length === 0)

Give your agent this brain