BrowserWindow
An application window that displays content of a Browser instance associated with it.
import { BrowserWindow } from '@mobrowser/api';
Example
import { app, BrowserWindow } from '@mobrowser/api';
const win: BrowserWindow = app.createWindow()
win.browser.loadUrl(app.url)
win.show()
Properties
browser
readonly browser: Browser;
The browser instance associated with the browser window.
title
readonly title: string;
The current title of the window.
position
readonly position: Point;
The current position of the window on the screen.
Example
import { app } from '@mobrowser/api';
const win = app.createWindow()
win.show()
console.log(`Window position: ${win.position.x}, ${win.position.y}`)
size
readonly size: Size;
The current size of the window.
Example
Persist the window size before closing so it can be restored on next launch:
import { app } from '@mobrowser/api';
const win = app.createWindow()
win.show()
console.log(`Window size: ${win.size.width}, ${win.size.height}`)
bounds
readonly bounds: Rect;
The current bounds of the window on the screen.
isFocused
readonly isFocused: boolean;
Whether the window content is focused.
Example
import { app } from '@mobrowser/api';
const win = app.createWindow()
win.show()
console.log(`Window is focused: ${win.isFocused}`)
isActive
readonly isActive: boolean;
Whether the window is active.
isMaximized
readonly isMaximized: boolean;
Whether the window is maximized.
isMinimized
readonly isMinimized: boolean;
Whether the window is minimized.
isFullScreen
readonly isFullScreen: boolean;
Whether the window is in full screen mode.
isAlwaysOnTop
readonly isAlwaysOnTop: boolean;
Whether the window is always on top of other windows.
isClosed
readonly isClosed: boolean;
Whether the window is closed.
isWindowTitleVisible
readonly isWindowTitleVisible: boolean;
Whether the window title is visible.
isWindowTitlebarVisible
readonly isWindowTitlebarVisible: boolean;
Whether the window titlebar is visible.
windowDisplayPolicy
readonly windowDisplayPolicy: WindowDisplayPolicy;
The policy for displaying the window across multiple desktops.
isWindowAnimationEnabled
readonly isWindowAnimationEnabled: boolean;
Whether window animation is enabled when showing the window on macOS.
isActivationIndependenceEnabled
readonly isActivationIndependenceEnabled: boolean;
Whether the user can interact with the always on top window without causing the application to be activated on macOS.
isVisible
readonly isVisible: boolean;
Whether the window is visible.
Example
import { app } from '@mobrowser/api';
const win = app.createWindow()
win.show()
console.log(`Window is visible: ${win.isVisible}`)
vibrancyEffect
readonly vibrancyEffect: VibrancyEffect;
The vibrancy effect of the window on macOS.
Methods
setTitle()
setTitle(title: string): void;
Sets the title of the window.
| Parameter | Type | Description |
|---|---|---|
title | string | The title to set for the window. Can be an empty string. |
Example
import { app } from '@mobrowser/api';
const win = app.createWindow()
win.setTitle('My App')
show()
show(): void;
Shows the window if it is hidden, or brings it to the front if it is already visible.
Example
import { app } from '@mobrowser/api';
const win = app.createWindow()
win.show()
hide()
hide(): void;
Hides the window if it is visible.
Example
import { app } from '@mobrowser/api';
const win = app.createWindow()
win.show()
// do something ...
win.hide()
focus()
focus(): void;
Brings the window to the front and gives it focus.
blur()
blur(): void;
Removes the window from the front and gives focus to the next window.
maximize()
maximize(): void;
Maximizes the window.
Example
import { app } from '@mobrowser/api';
const win = app.createWindow()
win.show()
win.maximize()
minimize()
minimize(): void;
Minimizes the window.
Example
import { app } from '@mobrowser/api';
const win = app.createWindow()
win.show()
win.minimize()
restore()
restore(): void;
Restores the window to its previous size.
Example
import { app } from '@mobrowser/api';
const win = app.createWindow()
win.show()
win.minimize()
win.restore()
enterFullScreen()
enterFullScreen(): void;
Enters full screen mode.
Example
import { app } from '@mobrowser/api';
const win = app.createWindow()
win.enterFullScreen()
win.show()
exitFullScreen()
exitFullScreen(): void;
Exits full screen mode.
setPosition()
setPosition(position: Point): void;
Sets the position of the window.
| Parameter | Type | Description |
|---|---|---|
position | Point | The position to set for the window. |
Example
import { app } from '@mobrowser/api';
const win = app.createWindow()
win.setPosition({ x: 800, y: 600 })
win.show()
setSize()
setSize(size: Size): void;
Sets the size of the window.
| Parameter | Type | Description |
|---|---|---|
size | Size | The size to set for the window. |
Example
import { app } from '@mobrowser/api';
const win = app.createWindow()
win.setSize({ width: 800, height: 600 })
win.show()
setBounds()
setBounds(bounds: Rect): void;
Sets the bounds of the window.
| Parameter | Type | Description |
|---|---|---|
bounds | Rect | The bounds to set for the window. |
Example
import { app } from '@mobrowser/api';
const win = app.createWindow()
win.setBounds({ origin: { x: 800, y: 600 }, size: { width: 800, height: 600 } })
win.show()
centerWindow()
centerWindow(): void;
Centers the window on the screen where it is located.
Example
import { app } from '@mobrowser/api';
const win = app.createWindow()
win.centerWindow()
win.show()
setAlwaysOnTop()
setAlwaysOnTop(alwaysOnTop: boolean): void;
Sets whether the window should be always on top of other windows.
| Parameter | Type | Description |
|---|---|---|
alwaysOnTop | boolean | Whether the window should be always on top. |
Example
import { app } from '@mobrowser/api';
const win = app.createWindow()
win.setAlwaysOnTop(true)
win.show()
setWindowTitleVisible()
setWindowTitleVisible(visible: boolean): void;
Sets whether the window title is visible.
| Parameter | Type | Description |
|---|---|---|
visible | boolean | Whether the window title should be visible. |
Example
import { app } from '@mobrowser/api';
const win = app.createWindow()
win.setWindowTitleVisible(true)
win.show()
setWindowTitlebarVisible()
setWindowTitlebarVisible(visible: boolean): void;
Sets whether the window titlebar is visible.
| Parameter | Type | Description |
|---|---|---|
visible | boolean | Whether the window titlebar should be visible. |
Example
import { app } from '@mobrowser/api';
const win = app.createWindow()
win.setWindowTitlebarVisible(true)
win.show()
setWindowDisplayPolicy()
setWindowDisplayPolicy(policy: WindowDisplayPolicy): void;
Sets the policy for displaying the window across multiple desktops.
This functionality is available on macOS only. On Windows and Linux the method does nothing.
| Parameter | Type | Description |
|---|---|---|
policy | WindowDisplayPolicy | The policy for displaying the window across multiple desktops. |
Example
import { app } from '@mobrowser/api';
const win = app.createWindow()
win.setWindowDisplayPolicy('appearOnAllDesktops')
win.show()
setWindowButtonVisible()
setWindowButtonVisible(button: WindowButtonType, visible: boolean): void;
Sets whether the window button of the given type is visible.
| Parameter | Type | Description |
|---|---|---|
button | WindowButtonType | The type of the window button. |
visible | boolean | Whether the window button is visible. |
Example
import { app } from '@mobrowser/api';
const win = app.createWindow()
win.setWindowButtonVisible('close', true)
win.show()
isWindowButtonVisible()
isWindowButtonVisible(button: WindowButtonType): boolean;
Checks if the window button of the given type is visible.
| Parameter | Type | Description |
|---|---|---|
button | WindowButtonType | The type of the window button. |
setWindowAnimationEnabled()
setWindowAnimationEnabled(enabled: boolean): void;
Allows enabling or disabling the default window animation when showing the browser window on macOS.
| Parameter | Type | Description |
|---|---|---|
enabled | boolean | Whether window animation should be enabled. |
Example
import { app } from '@mobrowser/api';
const win = app.createWindow()
win.setWindowAnimationEnabled(true)
win.show()
setActivationIndependenceEnabled()
setActivationIndependenceEnabled(enabled: boolean): void;
Specifies whether the user can interact with the always on top window without causing the application to be activated on macOS. Does nothing if the window is not configured to be always on top.
| Parameter | Type | Description |
|---|---|---|
enabled | boolean | Whether activation independence should be enabled. |
Example
import { app } from '@mobrowser/api';
const win = app.createWindow()
win.setActivationIndependenceEnabled(true)
win.show()
setVibrancyEffect()
setVibrancyEffect(effect: VibrancyEffect): void;
Sets the vibrancy effect of the window on macOS.
| Parameter | Type | Description |
|---|---|---|
effect | VibrancyEffect | The vibrancy effect to set for the window. |
Example
import { app } from '@mobrowser/api';
const win = app.createWindow()
win.setVibrancyEffect('titlebar')
win.show()
close()
close(): void;
Try to close the window. It is the same as a user clicking the close button of the window.
The window will try to close all its browser instances. If all browser instances are closed successfully, the window will be closed. If some browser instance cancels the close request, the window will stay open.
Example
import { app } from '@mobrowser/api';
const win = app.createWindow()
win.show()
// do something ...
win.close()
Events
’titleChanged'
on(event: 'titleChanged', listener: () => void): void;
off(event: 'titleChanged', listener: () => void): void;
Emitted when the window title is changed.
Example
import { app } from '@mobrowser/api';
const win = app.createWindow()
win.on('titleChanged', (title: string) => {
console.log('Window title changed')
})
win.show()
win.setTitle('New Title')
‘closed’
on(event: 'closed', listener: () => void): void;
off(event: 'closed', listener: () => void): void;
Emitted when the window is closed. After you receive this event, the window object will be destroyed, so you should remove any references to it and avoid using it.
Example
import { app } from '@mobrowser/api';
const win = app.createWindow()
win.on('closed', () => {
console.log('Window is closed')
})
win.show()
// do something ...
win.close()
‘focused’
on(event: 'focused', listener: () => void): void;
off(event: 'focused', listener: () => void): void;
Emitted when the window gains focus.
Example
import { app } from '@mobrowser/api';
const win = app.createWindow()
win.on('focused', () => {
console.log('Window is focused')
})
win.show()
‘blurred’
on(event: 'blurred', listener: () => void): void;
off(event: 'blurred', listener: () => void): void;
Emitted when the window loses focus.
Example
import { app } from '@mobrowser/api';
const win = app.createWindow()
win.on('blurred', () => {
console.log('Window is blurred')
})
win.show()
// do something ...
win.blur() // or click on another window
‘hidden’
on(event: 'hidden', listener: () => void): void;
off(event: 'hidden', listener: () => void): void;
Emitted when the window is hidden.
Example
import { app } from '@mobrowser/api';
const win = app.createWindow()
win.on('hidden', () => {
console.log('Window is hidden')
})
win.show()
// do something ...
win.hide()
‘shown’
on(event: 'shown', listener: () => void): void;
off(event: 'shown', listener: () => void): void;
Emitted when the window is shown.
Example
import { app } from '@mobrowser/api';
const win = app.createWindow()
win.on('shown', () => {
console.log('Window is shown')
})
win.show()
‘resized’
on(event: 'resized', listener: (newSize: Size) => void): void;
off(event: 'resized', listener: (newSize: Size) => void): void;
Emitted when the window is resized. newSize: The new size of the window.
Example
import { app } from '@mobrowser/api';
const win = app.createWindow()
win.on('resized', (newSize: Size) => {
console.log('Window is resized')
})
win.show()
win.setSize({ width: 800, height: 600 }) // or by resizing the window
‘moved’
on(event: 'moved', listener: (newPosition: Point) => void): void;
off(event: 'moved', listener: (newPosition: Point) => void): void;
Emitted when the window is moved to a new position. newPosition: The new position of the window.
Example
import { app } from '@mobrowser/api';
const win = app.createWindow()
win.on('moved', (newPosition: Point) => {
console.log('Window is moved')
})
win.show()
win.setPosition({ x: 800, y: 600 })
‘minimized’
on(event: 'minimized', listener: () => void): void;
off(event: 'minimized', listener: () => void): void;
Emitted when the window is minimized.
Example
import { app } from '@mobrowser/api';
const win = app.createWindow()
win.on('minimized', () => {
console.log('Window is minimized')
})
win.show()
win.minimize()
‘maximized’
on(event: 'maximized', listener: () => void): void;
off(event: 'maximized', listener: () => void): void;
Emitted when the window is maximized.
Example
import { app } from '@mobrowser/api';
const win = app.createWindow()
win.on('maximized', () => {
console.log('Window is maximized')
})
win.show()
win.maximize()
‘restored’
on(event: 'restored', listener: () => void): void;
off(event: 'restored', listener: () => void): void;
Emitted when the window is restored from minimized or maximized state.
Example
import { app } from '@mobrowser/api';
const win = app.createWindow()
win.on('restored', () => {
console.log('Window is restored')
})
win.show()
win.minimize()
win.restore()