on

fun on(event: BrowserWindowEvent.ALWAYS_ON_TOP_CHANGED, listener: (event: Event<*>, isAlwaysOnTop: Boolean) -> Unit)(source)

Emitted when the window is set or unset to show always on top of other windows.


fun on(event: BrowserWindowEvent.APP_COMMAND, listener: (event: Event<*>, command: String) -> Unit)(source)

Emitted when an App Command is invoked. These 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. e.g. APPCOMMAND_BROWSER_BACKWARD is emitted as browser-backward.

The following app commands are explicitly supported on Linux:

  • browser-backward

  • browser-forward


fun on(event: BrowserWindowEvent.BLUR, listener: Function<Unit>)(source)

Emitted when the window loses focus.


fun on(event: BrowserWindowEvent.CLOSE, listener: (event: Event<*>) -> Unit)(source)

Emitted when the window is going to be closed. It's emitted before the beforeunload and unload event of the DOM. Calling event.preventDefault() will cancel the close.

Usually you would want to use the beforeunload handler to decide whether the window should be closed, which will also be called when the window is reloaded. In Electron, returning any value other than undefined would cancel the close. For example:

Note: There is a subtle difference between the behaviors of window.onbeforeunload = handler and window.addEventListener('beforeunload', handler). It is recommended to always set the event.returnValue explicitly, instead of only returning a value, as the former works more consistently within Electron.


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


Emitted when the window enters a full-screen state.


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


Emitted when the window gains focus.


fun on(event: BrowserWindowEvent.HIDE, listener: Function<Unit>)(source)

Emitted when the window is hidden.


Emitted when the window leaves a full-screen state.


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


Emitted when window is maximized.


Emitted when the window is minimized.


fun on(event: BrowserWindowEvent.MOVE, listener: Function<Unit>)(source)

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


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

Note: On macOS this event is an alias of move.


Emitted when the native new tab button is clicked.


fun on(event: BrowserWindowEvent.PAGE_TITLE_UPDATED, listener: (event: Event<*>, title: String, explicitSet: Boolean) -> Unit)(source)

Emitted when the document changed its title, calling event.preventDefault() will prevent the native window's title from changing. explicitSet is false when title is synthesized from file URL.


Emitted when the web page has been rendered (while not being shown) and window can be displayed without a visual flash.

Please note that using this event implies that the renderer will be considered "visible" and paint even though show is false. This event will never fire if you use paintWhenInitiallyHidden: false


Emitted after the window has been resized.


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.


Emitted when the unresponsive web page becomes responsive again.


Emitted when the window is restored from a minimized state.


fun on(event: BrowserWindowEvent.ROTATE_GESTURE, listener: (event: Event<*>, rotation: Double) -> Unit)(source)

Emitted on trackpad rotation gesture. Continually emitted until rotation gesture is ended. The rotation value on each emission is the angle in degrees rotated since the 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.


Emitted when window session is going to end due to force shutdown or machine restart or session log off.


Emitted when the window opens a sheet.


Emitted when the window has closed a sheet.


fun on(event: BrowserWindowEvent.SHOW, listener: Function<Unit>)(source)

Emitted when the window is shown.


fun on(event: BrowserWindowEvent.SWIPE, listener: (event: Event<*>, direction: String) -> Unit)(source)

Emitted on 3-finger swipe. Possible directions are up, right, down, left.

The method underlying this event is built to handle older macOS-style trackpad swiping, where the content on the screen doesn't move with the swipe. Most macOS trackpads are not configured to allow this kind of swiping anymore, so in order 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'.


fun on(event: BrowserWindowEvent.SYSTEM_CONTEXT_MENU, listener: (event: Event<*>, point: Point) -> Unit)(source)

Emitted when the system context menu is triggered on the window, this is normally only triggered when the user right clicks on the non-client area of your window. This is the window titlebar or any area you have declared as -webkit-app-region: drag in a frameless window.

Calling event.preventDefault() will prevent the menu from being displayed.


Emitted when the window exits from a maximized state.


Emitted when the web page becomes unresponsive.


fun on(event: BrowserWindowEvent.WILL_MOVE, listener: (event: Event<*>, newBounds: Rectangle) -> Unit)(source)

Emitted before the window is moved. On Windows, calling event.preventDefault() will prevent the window from being moved.

Note that this is only emitted when the window is being moved manually. Moving the window with setPosition/setBounds/center will not emit this event.


fun on(event: BrowserWindowEvent.WILL_RESIZE, listener: (event: Event<*>, newBounds: Rectangle, details: WillResizeDetails) -> Unit)(source)

Emitted before the window is resized. Calling event.preventDefault() will prevent the window from being resized.

Note that this is only emitted when the window is being resized manually. Resizing the window with setBounds/setSize will not emit this event.

The possible values and behaviors of the edge option are platform dependent. Possible values are:

  • On Windows, possible values are bottom, top, left, right, top-left, top-right, bottom-left, bottom-right.

  • On macOS, possible values are bottom and right.

  • The value bottom is used to denote vertical resizing.

  • The value right is used to denote horizontal resizing.