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

webcontents: lifecycle & properties

155 notes in this subject, read out of this brain and free to use. This is page 1 of 3.

win.restore() method

Restores the window from minimized state to its previous state.

win.isMinimized() method

Returns boolean - whether the window is minimized.

win.setMovable(movable) - macOS Windows only

Sets whether the window can be moved by the user. On Linux this method does nothing.

win.isMovable() - macOS Windows only

Returns a boolean indicating whether the window can be moved by the user. On Linux this method always returns true.

win.setMinimizable(minimizable) - macOS Windows only

Sets whether the window can be manually minimized by the user. On Linux this method does nothing.

win.isFullScreenable()

Returns a boolean indicating whether the maximize/zoom window button toggles fullscreen mode or maximizes the window.

win.setClosable(closable) - macOS Windows only

Sets whether the window can be manually closed by the user. On Linux this method does nothing.

win.isMinimizable() - macOS Windows only

Returns a boolean indicating whether the window can be manually minimized by the user. On Linux this method always returns true.

win.setMaximizable(maximizable) - macOS Windows only

Sets whether the window can be manually maximized by the user. On Linux this method does nothing.

win.isMaximizable() - macOS Windows only

Returns a boolean indicating whether the window can be manually maximized by the user. On Linux this method always returns true.

Modal windows platform differences

On macOS, modal windows are displayed as sheets attached to the parent window. On Linux, the type of modal windows will be changed to 'dialog', and many desktop environments do not support hiding a modal window.

win.focusable property (Windows, macOS)

A boolean property that determines whether the window is focusable.

ready-to-show event timing

The 'ready-to-show' event is emitted when the renderer process has rendered the page for the first time if the window has not been shown yet. This event is usually emitted after the 'did-finish-load' event, but for pages with many remote resources, it may be emitted before the 'did-finish-load' event. Using this event implies the renderer will be considered 'visible' and paint even though show is false. This event will never fire if you use paintWhenInitiallyHidden: false.

Window display without visual flash using ready-to-show

To show a window without visual flash, create a BrowserWindow with show: false, then listen for the ready-to-show event and call win.show() in the event handler.

Parent and child windows

Child windows can be created by passing the parent option to the BrowserWindow constructor. The child window will always show on top of the parent window.

Modal windows

A modal window is a child window that disables the parent window. To create a modal window, set both the 'parent' and 'modal' options in the BrowserWindow constructor.

Page Visibility API behavior in Electron

On all platforms, the visibility state tracks whether the window is hidden/minimized or not. On macOS, the visibility state also tracks window occlusion—if the window is fully covered by another window, visibility state is 'hidden'. On other platforms, visibility state is 'hidden' only when the window is minimized or explicitly hidden with win.hide(). If a BrowserWindow is created with show: false, the initial visibility state will be 'visible' despite the window being hidden. If backgroundThrottling is disabled, the visibility state will remain 'visible' even if the window is minimized, occluded, or hidden. It is recommended to pause expensive operations when visibility state is 'hidden' to minimize power consumption.

Child windows platform differences

On macOS, child windows keep the relative position to the parent window when the parent window moves. On Windows and Linux, child windows do not move when the parent window moves.

Wayland window manipulation limitations

On Wayland (Linux), it is generally not possible to programmatically resize windows after creation, or to position, move, focus, or blur windows without user input. If your app needs these capabilities, run it in Xwayland by appending the flag --ozone-platform=x11.

Event: page-title-updated

Emitted when the document changed its title. Returns: event Event, title string, explicitSet boolean. Calling event.preventDefault() will prevent the native window's title from changing. explicitSet is false when title is synthesized from file URL.

Event: close

Emitted when the window is going to be closed, before the beforeunload and unload event of the DOM. Calling event.preventDefault() will cancel the close. In Electron, returning any value other than undefined from window.onbeforeunload will cancel the close. It is recommended to use event.returnValue explicitly rather than only returning a value, as the former works more consistently within Electron. Using the dialog API to let the user confirm closing is recommended.

Event: closed

Emitted when the window is closed. After receiving this event, you should remove the reference to the window and avoid using it any more.

Event: query-session-end (Windows)

Emitted when a session is about to end due to a shutdown, machine restart, or user log-off. Returns: event WindowSessionEndEvent. Calling event.preventDefault() can delay the system shutdown, though it is generally best to respect the user's choice. You may use it if ending the session puts the user at risk of losing data.

Event: session-end (Windows)

Emitted when a session is about to end due to a shutdown, machine restart, or user log-off. Returns: event WindowSessionEndEvent. Once this event fires, there is no way to prevent the session from ending.

Event: unresponsive

Emitted when the web page becomes unresponsive.

Event: responsive

Emitted when the unresponsive web page becomes responsive again.

Event: blur

Emitted when the window loses focus.

Event: focus

Emitted when the window gains focus.

Event: show

Emitted when the window is shown.

Event: hide

Emitted when the window is hidden.

Event: maximize

Emitted when window is maximized.

Event: unmaximize

Emitted when the window exits from a maximized state.

Event: minimize

Emitted when the window is minimized. On Wayland, 'minimized' is not currently a supported state. The minimize event will only fire when triggered by client-side decoration (e.g. clicking the minimize button on a frameless window's Window Control Overlay).

Event: restore

Emitted when the window is restored from a minimized state.

win.visibleOnAllWorkspaces property (macOS, Linux)

A boolean property that determines whether the window is visible on all workspaces. Always returns false on Windows.

Event: will-resize (macOS, Windows)

Emitted before the window is resized. Returns: event Event, newBounds Rectangle (size the window is being resized to), details Object with edge property (string indicating which edge is being dragged: bottom, left, right, top-left, top-right, bottom-left, or bottom-right). Calling event.preventDefault() will prevent the window from being resized. This is only emitted when the window is being resized manually; resizing with setBounds/setSize will not emit this event. On Windows, possible edge values are: bottom, top, left, right, top-left, top-right, bottom-left, bottom-right. On macOS, possible edge values are: bottom (vertical resizing) and right (horizontal resizing).

Event: resize

Emitted after the window has been resized.

Event: resized (macOS, Windows)

Emitted once when the window has finished being resized. This is usually emitted when the window has been resized manually. On macOS, resizing the window with setBounds/setSize and setting the animate parameter to true will also emit this event once resizing has finished.

Event: will-move (macOS, Windows)

Emitted before the window is moved. Returns: event Event, newBounds Rectangle (location the window is being moved to). On Windows, calling event.preventDefault() will prevent the window from being moved. This is only emitted when the window is being moved manually; moving with setPosition/setBounds/center will not emit this event.

Event: move

Emitted when the window is being moved to a new position.

Event: moved (macOS, Windows)

Emitted once when the window is moved to a new position. On macOS, this event is an alias of move.

Event: leave-full-screen

Emitted when the window leaves a full-screen state.

Event: leave-html-full-screen

Emitted when the window leaves a full-screen state triggered by HTML API.

Event: always-on-top-changed

Emitted when the window is set or unset to show always on top of other windows. Returns: event Event, isAlwaysOnTop boolean.

Event: app-command (Windows, Linux)

Emitted when an App Command is invoked. Returns: event Event, command string. App commands are typically related to keyboard media keys or browser commands, as well as the 'Back' button built into some mice on Windows. Commands are lowercased, underscores are replaced with hyphens, and the APPCOMMAND_ prefix is stripped off. For example, APPCOMMAND_BROWSER_BACKWARD is emitted as browser-backward. On Linux, the following app commands are explicitly supported: browser-backward, browser-forward.

Event: swipe (macOS)

Emitted on 3-finger swipe. Returns: event Event, direction string (possible directions: up, right, down, left). The method underlying this event is built to handle older macOS-style trackpad swiping where content doesn't move with the swipe. Most macOS trackpads are not configured this way anymore, so for it to emit properly, the 'Swipe between pages' preference in System Preferences > Trackpad > More Gestures must be set to 'Swipe with two or three fingers'.

Event: rotate-gesture (macOS)

Emitted on trackpad rotation gesture. Continually emitted until rotation gesture ends. Returns: event Event, rotation Float (angle in degrees rotated since last emission). The last emitted event upon a rotation gesture will always be of value 0. Counter-clockwise rotation values are positive, while clockwise ones are negative.

Event: sheet-begin (macOS)

Emitted when the window opens a sheet.

Event: sheet-end (macOS)

Emitted when the window has closed a sheet.

Event: new-window-for-tab (macOS)

Emitted when the user clicks the native macOS new tab button. The new tab button is only visible if the current BrowserWindow has a tabbingIdentifier. You must create a window in this handler in order for macOS tabbing to work as expected.

Event: system-context-menu (Windows, Linux)

Emitted when the system context menu is triggered on the window. Returns: event Event, point Point (screen coordinates where the context menu was triggered). This is normally only triggered when the user right clicks on the non-client area of the window—the window titlebar or any area declared as -webkit-app-region: drag in a frameless window. Calling event.preventDefault() will prevent the menu from being displayed. To convert point to DIP, use screen.screenToDipPoint(point).

win.webContents property

A read-only WebContents object that this window owns. All web page related events and operations are done via it.

win.id property

A read-only Integer property representing the unique ID of the window. Each ID is unique among all BrowserWindow instances of the entire Electron application.

win.autoHideMenuBar property (Linux, Windows)

A boolean property that determines whether the window menu bar should hide itself automatically. Once set to true, the menu bar will only show when users press the single Alt key. If the menu bar is already visible, setting this property to true won't hide it immediately.

win.simpleFullScreen property

A boolean property that determines whether the window is in simple (pre-Lion) fullscreen mode.

win.fullScreen property

A boolean property that determines whether the window is in fullscreen mode.

win.menuBarVisible property (Windows, Linux)

A boolean property that determines whether the menu bar should be visible. If the menu bar is auto-hide, users can still bring up the menu bar by pressing the single Alt key.

win.kiosk property

A boolean property that determines whether the window is in kiosk mode.

win.title property

A string property that determines the title of the native window. The title of the web page can be different from the title of the native window.

win.shadow property

A boolean property that determines whether the window has a shadow.

Give your agent this brain