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#

+ Privatenew WebviewWindow(label: string, options?: WindowOptions): WebviewWindow

Parameters:#

NameTypeDefault value
labelstring-
optionsWindowOptions{}

Returns: WebviewWindow

Overrides: WebviewWindowHandle

Defined in: window.ts:234

Properties#

label#

label: string

Window label.

Inherited from: WebviewWindowHandle.label

Defined in: window.ts:126


listeners#

listeners: object

Local event listeners.

Type declaration:#

Inherited from: WebviewWindowHandle.listeners

Defined in: window.ts:128

Methods#

_handleTauriEvent#

_handleTauriEvent<T>(event: string, handler: EventCallback<T>): boolean

Type parameters:#

Name
T

Parameters:#

NameType
eventstring
handlerEventCallback<T>

Returns: boolean

Inherited from: WebviewWindowHandle

Defined in: window.ts:192


emit#

emit(event: string, payload?: string): 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: WebviewWindowHandle

Defined in: window.ts:181


listen#

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

Listen to an 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: WebviewWindowHandle

Defined in: window.ts:143


once#

once<T>(event: string, handler: EventCallback<T>): 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: WebviewWindowHandle

Defined in: window.ts:164


getByLabel#

StaticgetByLabel(label: string): null | WebviewWindowHandle

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

Parameters:#

NameTypeDescription
labelstringThe webview window label.

Returns: null | WebviewWindowHandle

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

Defined in: window.ts:259