Skip to content
Tauri

webviewWindow

References

DragDropEvent

Re-exports DragDropEvent

DragDropPayload

Re-exports DragDropPayload

Classes

WebviewWindow

Create new webview or get a handle to an existing one.

Webviews are identified by a label a unique identifier that can be used to reference it later. It may only contain alphanumeric characters a-zA-Z plus the following special characters -, /, : and _.

Example

import { Window } from "@tauri-apps/api/window"
import { Webview } from "@tauri-apps/api/webview"
const appWindow = new Window('uniqueLabel');
// loading embedded asset:
const webview = new Webview(appWindow, 'theUniqueLabel', {
url: 'path/to/page.html'
});
// alternatively, load a remote URL:
const webview = new Webview(appWindow, 'theUniqueLabel', {
url: 'https://github.com/tauri-apps/tauri'
});
webview.once('tauri://created', function () {
// webview successfully created
});
webview.once('tauri://error', function (e) {
// an error happened creating the webview
});
// 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();

Since

2.0.0

Extends

Constructors

new WebviewWindow()
new WebviewWindow(label, options): WebviewWindow

Creates a new Window hosting a Webview.

Parameters
ParameterTypeDescription
labelstringThe unique webview label. Must be alphanumeric: a-zA-Z-/:_.
optionsOmit<WebviewOptions, "width" | "height" | "x" | "y"> & WindowOptions-
Returns

WebviewWindow

The WebviewWindow instance to communicate with the window and webview.

Inherited from

Window.constructor

Example
import { WebviewWindow } from '@tauri-apps/api/webviewWindow'
const webview = new WebviewWindow('my-label', {
url: 'https://github.com/tauri-apps/tauri'
});
webview.once('tauri://created', function () {
// webview successfully created
});
webview.once('tauri://error', function (e) {
// an error happened creating the webview
});

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/webviewWindow.ts#L74

Properties

PropertyTypeDescriptionInherited from
labelstringThe webview label. It is a unique identifier for the webview, can be used to reference it later.Window.label
listenersRecord<string, EventCallback<any>[]>Local event listeners.Window.listeners
windowWindowThe window hosting this webview.Webview.window

Methods

center()
center(): Promise<void>

Centers the window.

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from

Window.center

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().center();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L801

clearEffects()
clearEffects(): Promise<void>

Clear any applied effects if possible.

Returns

Promise<void>

Inherited from

Window.clearEffects

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1152

close()
close(): Promise<void>

Closes the webview.

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from

Window.close

Example
import { getCurrent } from '@tauri-apps/api/webview';
await getCurrent().close();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/webview.ts#L396

destroy()
destroy(): Promise<void>

Destroys the window. Behaves like Window.close but forces the window close instead of emitting a closeRequested event.

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from

Window.destroy

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().destroy();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1089

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

Emits an event to all targets.

Parameters
ParameterTypeDescription
eventstringEvent name. Must include only alphanumeric characters, -, /, : and _.
payload?unknownEvent payload.
Returns

Promise<void>

Inherited from

Window.emit

Example
import { getCurrent } from '@tauri-apps/api/webview';
await getCurrent().emit('webview-loaded', { loggedIn: true, token: 'authToken' });

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/webview.ts#L285

emitTo()
emitTo(
target,
event,
payload?): Promise<void>

Emits an event to all targets matching the given target.

Parameters
ParameterTypeDescription
targetstring | EventTargetLabel of the target Window/Webview/WebviewWindow or raw EventTarget object.
eventstringEvent name. Must include only alphanumeric characters, -, /, : and _.
payload?unknownEvent payload.
Returns

Promise<void>

Inherited from

Window.emitTo

Example
import { getCurrent } from '@tauri-apps/api/webview';
await getCurrent().emitTo('main', 'webview-loaded', { loggedIn: true, token: 'authToken' });

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/webview.ts#L313

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

Window.hide

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().hide();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1055

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>

The window’s inner position.

Inherited from

Window.innerPosition

Example
import { getCurrent } from '@tauri-apps/api/window';
const position = await getCurrent().innerPosition();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L519

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>

The window’s inner size.

Inherited from

Window.innerSize

Example
import { getCurrent } from '@tauri-apps/api/window';
const size = await getCurrent().innerSize();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L552

isClosable()
isClosable(): Promise<boolean>

Gets the window’s native close button state.

Platform-specific

  • iOS / Android: Unsupported.
Returns

Promise<boolean>

Whether the window’s native close button is enabled or not.

Inherited from

Window.isClosable

Example
import { getCurrent } from '@tauri-apps/api/window';
const closable = await getCurrent().isClosable();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L732

isDecorated()
isDecorated(): Promise<boolean>

Gets the window’s current decorated state.

Returns

Promise<boolean>

Whether the window is decorated or not.

Inherited from

Window.isDecorated

Example
import { getCurrent } from '@tauri-apps/api/window';
const decorated = await getCurrent().isDecorated();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L653

isFocused()
isFocused(): Promise<boolean>

Gets the window’s current focus state.

Returns

Promise<boolean>

Whether the window is focused or not.

Inherited from

Window.isFocused

Example
import { getCurrent } from '@tauri-apps/api/window';
const focused = await getCurrent().isFocused();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L637

isFullscreen()
isFullscreen(): Promise<boolean>

Gets the window’s current fullscreen state.

Returns

Promise<boolean>

Whether the window is in fullscreen mode or not.

Inherited from

Window.isFullscreen

Example
import { getCurrent } from '@tauri-apps/api/window';
const fullscreen = await getCurrent().isFullscreen();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L591

isMaximizable()
isMaximizable(): Promise<boolean>

Gets the window’s native maximize button state.

Platform-specific

  • Linux / iOS / Android: Unsupported.
Returns

Promise<boolean>

Whether the window’s native maximize button is enabled or not.

Inherited from

Window.isMaximizable

Example
import { getCurrent } from '@tauri-apps/api/window';
const maximizable = await getCurrent().isMaximizable();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L690

isMaximized()
isMaximized(): Promise<boolean>

Gets the window’s current maximized state.

Returns

Promise<boolean>

Whether the window is maximized or not.

Inherited from

Window.isMaximized

Example
import { getCurrent } from '@tauri-apps/api/window';
const maximized = await getCurrent().isMaximized();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L621

isMinimizable()
isMinimizable(): Promise<boolean>

Gets the window’s native minimize button state.

Platform-specific

  • Linux / iOS / Android: Unsupported.
Returns

Promise<boolean>

Whether the window’s native minimize button is enabled or not.

Inherited from

Window.isMinimizable

Example
import { getCurrent } from '@tauri-apps/api/window';
const minimizable = await getCurrent().isMinimizable();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L711

isMinimized()
isMinimized(): Promise<boolean>

Gets the window’s current minimized state.

Returns

Promise<boolean>

Inherited from

Window.isMinimized

Example
import { getCurrent } from '@tauri-apps/api/window';
const minimized = await getCurrent().isMinimized();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L605

isResizable()
isResizable(): Promise<boolean>

Gets the window’s current resizable state.

Returns

Promise<boolean>

Whether the window is resizable or not.

Inherited from

Window.isResizable

Example
import { getCurrent } from '@tauri-apps/api/window';
const resizable = await getCurrent().isResizable();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L669

isVisible()
isVisible(): Promise<boolean>

Gets the window’s current visible state.

Returns

Promise<boolean>

Whether the window is visible or not.

Inherited from

Window.isVisible

Example
import { getCurrent } from '@tauri-apps/api/window';
const visible = await getCurrent().isVisible();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L748

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

Listen to an emitted event on this webivew window.

Type parameters
Type parameter
T
Parameters
ParameterTypeDescription
eventEventNameEvent name. Must include only alphanumeric characters, -, /, : and _.
handlerEventCallback<T>Event handler.
Returns

Promise<UnlistenFn>

A promise resolving to a function to unlisten to the event. Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.

Inherited from

Window.listen

Example
import { WebviewWindow } from '@tauri-apps/api/webviewWindow';
const unlisten = await WebviewWindow.getCurrent().listen<string>('state-changed', (event) => {
console.log(`Got error: ${payload}`);
});
// you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
unlisten();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/webviewWindow.ts#L154

maximize()
maximize(): Promise<void>

Maximizes the window.

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from

Window.maximize

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().maximize();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L959

minimize()
minimize(): Promise<void>

Minimizes the window.

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from

Window.minimize

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().minimize();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1007

onCloseRequested()
onCloseRequested(handler): Promise<UnlistenFn>

Listen to window close requested. Emitted when the user requests to closes the window.

Parameters
ParameterType
handler(event) => void | Promise<void>
Returns

Promise<UnlistenFn>

A promise resolving to a function to unlisten to the event. Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.

Inherited from

Window.onCloseRequested

Example
import { getCurrent } from "@tauri-apps/api/window";
import { confirm } from '@tauri-apps/api/dialog';
const unlisten = await getCurrent().onCloseRequested(async (event) => {
const confirmed = await confirm('Are you sure?');
if (!confirmed) {
// user did not confirm closing the window; let's prevent it
event.preventDefault();
}
});
// you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
unlisten();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1700

onDragDropEvent()
onDragDropEvent(handler): Promise<UnlistenFn>

Listen to a file drop event. The listener is triggered when the user hovers the selected files on the webview, drops the files or cancels the operation.

Parameters
ParameterType
handlerEventCallback<DragDropEvent>
Returns

Promise<UnlistenFn>

A promise resolving to a function to unlisten to the event. Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.

Inherited from

Window.onDragDropEvent

Example
import { getCurrent } from "@tauri-apps/api/webview";
const unlisten = await getCurrent().onDragDropEvent((event) => {
if (event.payload.type === 'hover') {
console.log('User hovering', event.payload.paths);
} else if (event.payload.type === 'drop') {
console.log('User dropped', event.payload.paths);
} else {
console.log('File drop cancelled');
}
});
// you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
unlisten();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/webview.ts#L544

onFocusChanged()
onFocusChanged(handler): Promise<UnlistenFn>

Listen to window focus change.

Parameters
ParameterType
handlerEventCallback<boolean>
Returns

Promise<UnlistenFn>

A promise resolving to a function to unlisten to the event. Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.

Inherited from

Window.onFocusChanged

Example
import { getCurrent } from "@tauri-apps/api/window";
const unlisten = await getCurrent().onFocusChanged(({ payload: focused }) => {
console.log('Focus changed, window is focused? ' + focused);
});
// you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
unlisten();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1815

onMoved()
onMoved(handler): Promise<UnlistenFn>

Listen to window move.

Parameters
ParameterType
handlerEventCallback<PhysicalPosition>
Returns

Promise<UnlistenFn>

A promise resolving to a function to unlisten to the event. Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.

Inherited from

Window.onMoved

Example
import { getCurrent } from "@tauri-apps/api/window";
const unlisten = await getCurrent().onMoved(({ payload: position }) => {
console.log('Window moved', position);
});
// you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
unlisten();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1670

onResized()
onResized(handler): Promise<UnlistenFn>

Listen to window resize.

Parameters
ParameterType
handlerEventCallback<PhysicalSize>
Returns

Promise<UnlistenFn>

A promise resolving to a function to unlisten to the event. Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.

Inherited from

Window.onResized

Example
import { getCurrent } from "@tauri-apps/api/window";
const unlisten = await getCurrent().onResized(({ payload: size }) => {
console.log('Window resized', size);
});
// you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
unlisten();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1646

onScaleChanged()
onScaleChanged(handler): Promise<UnlistenFn>

Listen to window scale change. Emitted when the window’s scale factor has changed. The following user actions can cause DPI changes:

  • Changing the display’s resolution.
  • Changing the display’s scale factor (e.g. in Control Panel on Windows).
  • Moving the window to a display with a different scale factor.
Parameters
ParameterType
handlerEventCallback<ScaleFactorChanged>
Returns

Promise<UnlistenFn>

A promise resolving to a function to unlisten to the event. Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.

Inherited from

Window.onScaleChanged

Example
import { getCurrent } from "@tauri-apps/api/window";
const unlisten = await getCurrent().onScaleChanged(({ payload }) => {
console.log('Scale changed', payload.scaleFactor, payload.size);
});
// you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
unlisten();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1855

onThemeChanged()
onThemeChanged(handler): Promise<UnlistenFn>

Listen to the system theme change.

Parameters
ParameterType
handlerEventCallback<Theme>
Returns

Promise<UnlistenFn>

A promise resolving to a function to unlisten to the event. Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.

Inherited from

Window.onThemeChanged

Example
import { getCurrent } from "@tauri-apps/api/window";
const unlisten = await getCurrent().onThemeChanged(({ payload: theme }) => {
console.log('New theme: ' + theme);
});
// you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
unlisten();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1881

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

Listen to an emitted event on this webview window only once.

Type parameters
Type parameter
T
Parameters
ParameterTypeDescription
eventstringEvent name. Must include only alphanumeric characters, -, /, : and _.
handlerEventCallback<T>Event handler.
Returns

Promise<UnlistenFn>

A promise resolving to a function to unlisten to the event. Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.

Inherited from

Window.once

Example
import { WebviewWindow } from '@tauri-apps/api/webviewWindow';
const unlisten = await WebviewWindow.getCurrent().once<null>('initialized', (event) => {
console.log(`Webview initialized!`);
});
// you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
unlisten();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/webviewWindow.ts#L189

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>

The window’s outer position.

Inherited from

Window.outerPosition

Example
import { getCurrent } from '@tauri-apps/api/window';
const position = await getCurrent().outerPosition();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L535

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>

The window’s outer size.

Inherited from

Window.outerSize

Example
import { getCurrent } from '@tauri-apps/api/window';
const size = await getCurrent().outerSize();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L572

position()
position(): Promise<PhysicalPosition>

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

Returns

Promise<PhysicalPosition>

The webview’s position.

Inherited from

Webview.position

Example
import { getCurrent } from '@tauri-apps/api/webview';
const position = await getCurrent().position();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/webview.ts#L358

reparent()
reparent(window): Promise<void>

Moves this webview to the given label.

Parameters
ParameterType
windowstring | Window | WebviewWindow
Returns

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from

Webview.reparent

Example
import { getCurrent } from '@tauri-apps/api/webview';
await getCurrent().reparent('other-window');

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/webview.ts#L510

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.
  • Linux: Urgency levels have the same effect.
Parameters
ParameterType
requestTypenull | UserAttentionType
Returns

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from

Window.requestUserAttention

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().requestUserAttention();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L827

scaleFactor()
scaleFactor(): Promise<number>

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

Returns

Promise<number>

The window’s monitor scale factor.

Inherited from

Window.scaleFactor

Example
import { getCurrent } from '@tauri-apps/api/window';
const factor = await getCurrent().scaleFactor();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L503

setAlwaysOnBottom()
setAlwaysOnBottom(alwaysOnBottom): Promise<void>

Whether the window should always be below other windows.

Parameters
ParameterTypeDescription
alwaysOnBottombooleanWhether the window should always be below other windows or not.
Returns

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from

Window.setAlwaysOnBottom

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().setAlwaysOnBottom(true);

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1188

setAlwaysOnTop()
setAlwaysOnTop(alwaysOnTop): Promise<void>

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

Parameters
ParameterTypeDescription
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

Window.setAlwaysOnTop

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().setAlwaysOnTop(true);

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1170

setClosable()
setClosable(closable): Promise<void>

Sets whether the window’s native close button is enabled or not.

Platform-specific

  • Linux: GTK+ will do its best to convince the window manager not to show a close button. Depending on the system, this function may not have any effect when called on a window that is already visible
  • iOS / Android: Unsupported.
Parameters
ParameterType
closableboolean
Returns

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from

Window.setClosable

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().setClosable(false);

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L924

setContentProtected()
setContentProtected(protected_): Promise<void>

Prevents the window contents from being captured by other apps.

Parameters
ParameterType
protected_boolean
Returns

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from

Window.setContentProtected

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().setContentProtected(true);

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1205

setCursorGrab()
setCursorGrab(grab): Promise<void>

Grabs the cursor, preventing it from leaving the window.

There’s no guarantee that the cursor will be hidden. You should hide it by yourself if you want so.

Platform-specific

  • Linux: Unsupported.
  • macOS: This locks the cursor in a fixed location, which looks visually awkward.
Parameters
ParameterTypeDescription
grabbooleantrue to grab the cursor icon, false to release it.
Returns

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from

Window.setCursorGrab

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().setCursorGrab(true);

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1449

setCursorIcon()
setCursorIcon(icon): Promise<void>

Modifies the cursor icon of the window.

Parameters
ParameterTypeDescription
iconCursorIconThe new cursor icon.
Returns

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from

Window.setCursorIcon

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().setCursorIcon('help');

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1491

setCursorPosition()
setCursorPosition(position): Promise<void>

Changes the position of the cursor in window coordinates.

Parameters
ParameterTypeDescription
positionLogicalPosition | PhysicalPositionThe new cursor position.
Returns

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from

Window.setCursorPosition

Example
import { getCurrent, LogicalPosition } from '@tauri-apps/api/window';
await getCurrent().setCursorPosition(new LogicalPosition(600, 300));

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1509

setCursorVisible()
setCursorVisible(visible): Promise<void>

Modifies the cursor’s visibility.

Platform-specific

  • Windows: The cursor is only hidden within the confines of the window.
  • macOS: The cursor is hidden as long as the window has input focus, even if the cursor is outside of the window.
Parameters
ParameterTypeDescription
visiblebooleanIf false, this will hide the cursor. If true, this will show the cursor.
Returns

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from

Window.setCursorVisible

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().setCursorVisible(false);

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1473

setDecorations()
setDecorations(decorations): Promise<void>

Whether the window should have borders and bars.

Parameters
ParameterTypeDescription
decorationsbooleanWhether the window should have borders and bars.
Returns

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from

Window.setDecorations

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().setDecorations(false);

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1106

setEffects()
setEffects(effects): Promise<void>

Set window effects.

Parameters
ParameterType
effectsEffects
Returns

Promise<void>

Inherited from

Window.setEffects

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1142

setFocus()
setFocus(): Promise<void>

Bring the webview to front and focus.

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from

Window.setFocus

Example
import { getCurrent } from '@tauri-apps/api/webview';
await getCurrent().setFocus();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/webview.ts#L477

setFullscreen()
setFullscreen(fullscreen): Promise<void>

Sets the window fullscreen state.

Parameters
ParameterTypeDescription
fullscreenbooleanWhether the window should go to fullscreen or not.
Returns

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from

Window.setFullscreen

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().setFullscreen(true);

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1358

setIcon()
setIcon(icon): Promise<void>

Sets the window icon.

Parameters
ParameterTypeDescription
icon| string | number[] | ArrayBuffer | Uint8Array | ImageIcon bytes or path to the icon file.
Returns

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from

Window.setIcon

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().setIcon('/tauri/awesome.png');

Note that you need the image-ico or image-png Cargo features to use this API. To enable it, change your Cargo.toml file:

[dependencies]
tauri = { version = "...", features = ["...", "image-png"] }

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1399

setIgnoreCursorEvents()
setIgnoreCursorEvents(ignore): Promise<void>

Changes the cursor events behavior.

Parameters
ParameterTypeDescription
ignorebooleantrue to ignore the cursor events; false to process them as usual.
Returns

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from

Window.setIgnoreCursorEvents

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().setIgnoreCursorEvents(true);

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1545

setMaxSize()
setMaxSize(size): Promise<void>

Sets the window maximum inner size. If the size argument is undefined, the constraint is unset.

Parameters
ParameterTypeDescription
sizeundefined | null | LogicalSize | PhysicalSizeThe logical or physical inner size, or null to unset the constraint.
Returns

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from

Window.setMaxSize

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

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1288

setMaximizable()
setMaximizable(maximizable): Promise<void>

Sets whether the window’s native maximize button is enabled or not. If resizable is set to false, this setting is ignored.

Platform-specific

  • macOS: Disables the “zoom” button in the window titlebar, which is also used to enter fullscreen mode.
  • Linux / iOS / Android: Unsupported.
Parameters
ParameterType
maximizableboolean
Returns

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from

Window.setMaximizable

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().setMaximizable(false);

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L879

setMinSize()
setMinSize(size): Promise<void>

Sets the window minimum inner size. If the size argument is not provided, the constraint is unset.

Parameters
ParameterTypeDescription
sizeundefined | null | LogicalSize | PhysicalSizeThe logical or physical inner size, or null to unset the constraint.
Returns

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from

Window.setMinSize

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

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1253

setMinimizable()
setMinimizable(minimizable): Promise<void>

Sets whether the window’s native minimize button is enabled or not.

Platform-specific

  • Linux / iOS / Android: Unsupported.
Parameters
ParameterType
minimizableboolean
Returns

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from

Window.setMinimizable

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().setMinimizable(false);

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L901

setPosition()
setPosition(position): Promise<void>

Sets the webview position.

Parameters
ParameterTypeDescription
positionLogicalPosition | PhysicalPositionThe new position, in logical or physical pixels.
Returns

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from

Window.setPosition

Example
import { getCurrent, LogicalPosition } from '@tauri-apps/api/webview';
await getCurrent().setPosition(new LogicalPosition(600, 500));

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/webview.ts#L443

setProgressBar()
setProgressBar(state): Promise<void>

Sets the taskbar progress state.

Platform-specific

  • Linux / macOS: Progress bar is app-wide and not specific to this window.
  • Linux: Only supported desktop environments with libunity (e.g. GNOME).
Parameters
ParameterType
stateProgressBarState
Returns

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from

Window.setProgressBar

Example
import { getCurrent, ProgressBarStatus } from '@tauri-apps/api/window';
await getCurrent().setProgressBar({
status: ProgressBarStatus.Normal,
progress: 50,
});

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1604

setResizable()
setResizable(resizable): Promise<void>

Updates the window resizable flag.

Parameters
ParameterType
resizableboolean
Returns

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from

Window.setResizable

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().setResizable(false);

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L855

setShadow()
setShadow(enable): Promise<void>

Whether or not the window should have shadow.

Platform-specific

  • Windows:
    • false has no effect on decorated window, shadows are always ON.
    • true will make ndecorated window have a 1px white border, and on Windows 11, it will have a rounded corners.
  • Linux: Unsupported.
Parameters
ParameterType
enableboolean
Returns

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from

Window.setShadow

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().setShadow(false);

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1132

setSize()
setSize(size): Promise<void>

Resizes the webview.

Parameters
ParameterTypeDescription
sizeLogicalSize | PhysicalSizeThe logical or physical size.
Returns

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from

Window.setSize

Example
import { getCurrent, LogicalSize } from '@tauri-apps/api/webview';
await getCurrent().setSize(new LogicalSize(600, 500));

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/webview.ts#L413

setSkipTaskbar()
setSkipTaskbar(skip): Promise<void>

Whether the window icon should be hidden from the taskbar or not.

Platform-specific

  • macOS: Unsupported.
Parameters
ParameterTypeDescription
skipbooleantrue to hide window icon, false to show it.
Returns

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from

Window.setSkipTaskbar

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().setSkipTaskbar(true);

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1423

setTitle()
setTitle(title): Promise<void>

Sets the window title.

Parameters
ParameterTypeDescription
titlestringThe new title
Returns

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from

Window.setTitle

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().setTitle('Tauri');

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L942

setVisibleOnAllWorkspaces()
setVisibleOnAllWorkspaces(visible): Promise<void>

Sets whether the window should be visible on all workspaces or virtual desktops.

Platform-specific

  • Windows / iOS / Android: Unsupported.
Parameters
ParameterType
visibleboolean
Returns

Promise<void>

Inherited from

Window.setVisibleOnAllWorkspaces

Since

2.0.0

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1620

setZoom()
setZoom(scaleFactor): Promise<void>

Set webview zoom level.

Parameters
ParameterType
scaleFactornumber
Returns

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from

Webview.setZoom

Example
import { getCurrent } from '@tauri-apps/api/webview';
await getCurrent().setZoom(1.5);

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/webview.ts#L493

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

Window.show

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().show();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1039

size()
size(): Promise<PhysicalSize>

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

Returns

Promise<PhysicalSize>

The webview’s size.

Inherited from

Webview.size

Example
import { getCurrent } from '@tauri-apps/api/webview';
const size = await getCurrent().size();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/webview.ts#L375

startDragging()
startDragging(): Promise<void>

Starts dragging the window.

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from

Window.startDragging

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().startDragging();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1562

startResizeDragging()
startResizeDragging(direction): Promise<void>

Starts resize-dragging the window.

Parameters
ParameterType
directionResizeDirection
Returns

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from

Window.startResizeDragging

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().startResizeDragging();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1578

theme()
theme(): Promise<null | Theme>

Gets the window’s current theme.

Platform-specific

  • macOS: Theme was introduced on macOS 10.14. Returns light on macOS 10.13 and below.
Returns

Promise<null | Theme>

The window theme.

Inherited from

Window.theme

Example
import { getCurrent } from '@tauri-apps/api/window';
const theme = await getCurrent().theme();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L783

title()
title(): Promise<string>

Gets the window’s current title.

Returns

Promise<string>

Inherited from

Window.title

Example
import { getCurrent } from '@tauri-apps/api/window';
const title = await getCurrent().title();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L762

toggleMaximize()
toggleMaximize(): Promise<void>

Toggles the window maximized state.

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from

Window.toggleMaximize

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().toggleMaximize();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L991

unmaximize()
unmaximize(): Promise<void>

Unmaximizes the window.

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from

Window.unmaximize

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().unmaximize();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L975

unminimize()
unminimize(): Promise<void>

Unminimizes the window.

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Inherited from

Window.unminimize

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().unminimize();

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1023

getAll()
static getAll(): WebviewWindow[]

Gets a list of instances of Webview for all available webviews.

Returns

WebviewWindow[]

Inherited from

Window.getAll

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/webviewWindow.ts#L130

getByLabel()
static getByLabel(label): null | WebviewWindow

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

Parameters
ParameterTypeDescription
labelstringThe webview label.
Returns

null | WebviewWindow

The Webview instance to communicate with the webview or null if the webview doesn’t exist.

Inherited from

Window.getByLabel

Example
import { Webview } from '@tauri-apps/api/webviewWindow';
const mainWebview = Webview.getByLabel('main');

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/webviewWindow.ts#L111

getCurrent()
static getCurrent(): WebviewWindow

Get an instance of Webview for the current webview.

Returns

WebviewWindow

Inherited from

Window.getCurrent

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/webviewWindow.ts#L123

Functions

getAll()

function getAll(): WebviewWindow[]

Gets a list of instances of Webview for all available webview windows.

Returns

WebviewWindow[]

Since

2.0.0

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/webviewWindow.ts#L34


getCurrent()

function getCurrent(): WebviewWindow

Get an instance of Webview for the current webview window.

Returns

WebviewWindow

Since

2.0.0

Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/webviewWindow.ts#L23


© 2024 Tauri Contributors. CC-BY / MIT