Skip to main content

window.WebviewWindow

Create new webview windows and get a handle to existing ones.

example

// loading embedded asset:
const webview = new WebviewWindow('theUniqueLabel', {
  url: 'path/to/page.html'
})
// alternatively, load a remote URL:
const webview = new WebviewWindow('theUniqueLabel', {
  url: 'https://github.com/tauri-apps/tauri'
})

webview.once('tauri://created', function () {
 // webview window successfully created
})
webview.once('tauri://error', function (e) {
 // an error happened creating the webview window
})

// emit an event to the backend
await webview.emit("some event", "data")
// listen to an event from the backend
const unlisten = await webview.listen("event name", e => {})
unlisten()

Hierarchy#

Constructors#

constructor#

new WebviewWindow(label, options?)

Parameters#

NameType
labelWindowLabel
optionsWindowOptions

Overrides#

WindowManager.constructor

Defined in#

window.ts:1095

Properties#

label#

label: WindowLabel

Window label.

Inherited from#

WindowManager.label

Defined in#

window.ts:229


listeners#

listeners: Object

Local event listeners.

Index signature#

▪ [key: string]: EventCallback<any>[]

Inherited from#

WindowManager.listeners

Defined in#

window.ts:231

Methods#

_handleTauriEvent#

_handleTauriEvent<T>(event, handler): boolean

Type parameters#

Name
T

Parameters#

NameType
eventstring
handlerEventCallback<T>

Returns#

boolean

Inherited from#

WindowManager._handleTauriEvent

Defined in#

window.ts:295


center#

center(): Promise<void>

Centers the window.

Returns#

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from#

WindowManager.center

Defined in#

window.ts:489


close#

close(): Promise<void>

Closes the window.

Returns#

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from#

WindowManager.close

Defined in#

window.ts:734


emit#

emit(event, payload?): Promise<void>

Emits an event to the backend, tied to the webview window.

Parameters#

NameTypeDescription
eventstringEvent name.
payload?stringEvent payload.

Returns#

Promise<void>

Inherited from#

WindowManager.emit

Defined in#

window.ts:284


hide#

hide(): Promise<void>

Sets the window visibility to false.

Returns#

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from#

WindowManager.hide

Defined in#

window.ts:714


innerPosition#

innerPosition(): Promise<PhysicalPosition>

The position of the top-left hand corner of the window's client area relative to the top-left hand corner of the desktop.

Returns#

Promise<PhysicalPosition>

Inherited from#

WindowManager.innerPosition

Defined in#

window.ts:332


innerSize#

innerSize(): Promise<PhysicalSize>

The physical size of the window's client area. The client area is the content of the window, excluding the title bar and borders.

Returns#

Promise<PhysicalSize>

Inherited from#

WindowManager.innerSize

Defined in#

window.ts:367


isDecorated#

isDecorated(): Promise<boolean>

Gets the window's current decorated state.

Returns#

Promise<boolean>

Inherited from#

WindowManager.isDecorated

Defined in#

window.ts:434


isFullscreen#

isFullscreen(): Promise<boolean>

Gets the window's current fullscreen state.

Returns#

Promise<boolean>

Inherited from#

WindowManager.isFullscreen

Defined in#

window.ts:402


isMaximized#

isMaximized(): Promise<boolean>

Gets the window's current maximized state.

Returns#

Promise<boolean>

Inherited from#

WindowManager.isMaximized

Defined in#

window.ts:418


isResizable#

isResizable(): Promise<boolean>

Gets the window's current resizable state.

Returns#

Promise<boolean>

Inherited from#

WindowManager.isResizable

Defined in#

window.ts:450


isVisible#

isVisible(): Promise<boolean>

Gets the window's current visible state.

Returns#

Promise<boolean>

Inherited from#

WindowManager.isVisible

Defined in#

window.ts:466


listen#

listen<T>(event, handler): Promise<UnlistenFn>

Listen to an event emitted by the backend that is tied to the webview window.

Type parameters#

Name
T

Parameters#

NameTypeDescription
eventEventNameEvent name.
handlerEventCallback<T>Event handler.

Returns#

Promise<UnlistenFn>

A promise resolving to a function to unlisten to the event.

Inherited from#

WindowManager.listen

Defined in#

window.ts:246


maximize#

maximize(): Promise<void>

Maximizes the window.

Returns#

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from#

WindowManager.maximize

Defined in#

window.ts:594


minimize#

minimize(): Promise<void>

Minimizes the window.

Returns#

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from#

WindowManager.minimize

Defined in#

window.ts:654


once#

once<T>(event, handler): Promise<UnlistenFn>

Listen to an one-off event emitted by the backend that is tied to the webview window.

Type parameters#

Name
T

Parameters#

NameTypeDescription
eventstringEvent name.
handlerEventCallback<T>Event handler.

Returns#

Promise<UnlistenFn>

A promise resolving to a function to unlisten to the event.

Inherited from#

WindowManager.once

Defined in#

window.ts:267


outerPosition#

outerPosition(): Promise<PhysicalPosition>

The position of the top-left hand corner of the window relative to the top-left hand corner of the desktop.

Returns#

Promise<PhysicalPosition>

Inherited from#

WindowManager.outerPosition

Defined in#

window.ts:348


outerSize#

outerSize(): Promise<PhysicalSize>

The physical size of the entire window. These dimensions include the title bar and borders. If you don't want that (and you usually don't), use inner_size instead.

Returns#

Promise<PhysicalSize>

Inherited from#

WindowManager.outerSize

Defined in#

window.ts:386


requestUserAttention#

requestUserAttention(requestType): Promise<void>

Requests user attention to the window, this has no effect if the application is already focused. How requesting for user attention manifests is platform dependent, see UserAttentionType for details.

Providing null will unset the request for user attention. Unsetting the request for user attention might not be done automatically by the WM when the window receives input.

Platform-specific#

  • macOS: null has no effect.

Parameters#

NameType
requestTypenull | UserAttentionType

Returns#

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from#

WindowManager.requestUserAttention

Defined in#

window.ts:519


scaleFactor#

scaleFactor(): Promise<number>

The scale factor that can be used to map physical pixels to logical pixels.

Returns#

Promise<number>

Inherited from#

WindowManager.scaleFactor

Defined in#

window.ts:316


setAlwaysOnTop#

setAlwaysOnTop(alwaysOnTop): Promise<void>

Whether the window should always be on top of other windows.

Parameters#

NameTypeDescription
alwaysOnTopbooleanWhether the window should always be on top of other windows or not.

Returns#

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from#

WindowManager.setAlwaysOnTop

Defined in#

window.ts:777


setDecorations#

setDecorations(decorations): Promise<void>

Whether the window should have borders and bars.

Parameters#

NameTypeDescription
decorationsbooleanWhether the window should have borders and bars.

Returns#

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from#

WindowManager.setDecorations

Defined in#

window.ts:755


setFocus#

setFocus(): Promise<void>

Bring the window to front and focus.

Returns#

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from#

WindowManager.setFocus

Defined in#

window.ts:985


setFullscreen#

setFullscreen(fullscreen): Promise<void>

Sets the window fullscreen state.

Parameters#

NameTypeDescription
fullscreenbooleanWhether the window should go to fullscreen or not.

Returns#

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from#

WindowManager.setFullscreen

Defined in#

window.ts:964


setIcon#

setIcon(icon): Promise<void>

Sets the window icon.

Parameters#

NameTypeDescription
iconstring | number[]Icon bytes or path to the icon file.

Returns#

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from#

WindowManager.setIcon

Defined in#

window.ts:1006


setMaxSize#

setMaxSize(size): Promise<void>

Sets the window max size. If the size argument is undefined, the max size is unset.

example

import { appWindow, LogicalSize } from '@tauri-apps/api/window'
await appWindow.setMaxSize(new LogicalSize(600, 500))

Parameters#

NameTypeDescription
sizeundefined | PhysicalSize | LogicalSizeThe logical or physical size.

Returns#

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from#

WindowManager.setMaxSize

Defined in#

window.ts:884


setMinSize#

setMinSize(size): Promise<void>

Sets the window min size. If the size argument is not provided, the min size is unset.

example

import { appWindow, PhysicalSize } from '@tauri-apps/api/window'
await appWindow.setMinSize(new PhysicalSize(600, 500))

Parameters#

NameTypeDescription
sizeundefined | PhysicalSize | LogicalSizeThe logical or physical size.

Returns#

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from#

WindowManager.setMinSize

Defined in#

window.ts:842


setPosition#

setPosition(position): Promise<void>

Sets the window position.

example

import { appWindow, LogicalPosition } from '@tauri-apps/api/window'
await appWindow.setPosition(new LogicalPosition(600, 500))

Parameters#

NameTypeDescription
positionPhysicalPosition | LogicalPositionThe new position, in logical or physical pixels.

Returns#

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from#

WindowManager.setPosition

Defined in#

window.ts:926


setResizable#

setResizable(resizable): Promise<void>

Updates the window resizable flag.

Parameters#

NameType
resizableboolean

Returns#

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from#

WindowManager.setResizable

Defined in#

window.ts:551


setSize#

setSize(size): Promise<void>

Resizes the window.

example

import { appWindow, LogicalSize } from '@tauri-apps/api/window'
await appWindow.setSize(new LogicalSize(600, 500))

Parameters#

NameTypeDescription
sizePhysicalSize | LogicalSizeThe logical or physical size.

Returns#

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from#

WindowManager.setSize

Defined in#

window.ts:804


setSkipTaskbar#

setSkipTaskbar(skip): Promise<void>

Whether to show the window icon in the task bar or not.

Parameters#

NameTypeDescription
skipbooleantrue to hide window icon, false to show it.

Returns#

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from#

WindowManager.setSkipTaskbar

Defined in#

window.ts:1030


setTitle#

setTitle(title): Promise<void>

Sets the window title.

Parameters#

NameTypeDescription
titlestringThe new title

Returns#

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from#

WindowManager.setTitle

Defined in#

window.ts:573


show#

show(): Promise<void>

Sets the window visibility to true.

Returns#

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from#

WindowManager.show

Defined in#

window.ts:694


startDragging#

startDragging(): Promise<void>

Starts dragging the window.

Returns#

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from#

WindowManager.startDragging

Defined in#

window.ts:1051


toggleMaximize#

toggleMaximize(): Promise<void>

Toggles the window maximized state.

Returns#

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from#

WindowManager.toggleMaximize

Defined in#

window.ts:634


unmaximize#

unmaximize(): Promise<void>

Unmaximizes the window.

Returns#

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from#

WindowManager.unmaximize

Defined in#

window.ts:614


unminimize#

unminimize(): Promise<void>

Unminimizes the window.

Returns#

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from#

WindowManager.unminimize

Defined in#

window.ts:674


getByLabel#

Static getByLabel(label): null | WebviewWindow

Gets the WebviewWindow for the webview associated with the given label.

Parameters#

NameTypeDescription
labelstringThe webview window label.

Returns#

null | WebviewWindow

The WebviewWindow instance to communicate with the webview or null if the webview doesn't exist.

Defined in#

window.ts:1122