跳转到内容
Tauri

webviewWindow

此内容尚不支持你的语言。

Re-exports Color

Re-exports DragDropEvent

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 _.

import { Window } from "@tauri-apps/api/window"
import { Webview } from "@tauri-apps/api/webview"
const appWindow = new Window('uniqueLabel');
appWindow.once('tauri://created', async function () {
// `new Webview` Should be called after the window is successfully created,
// or webview may not be attached to the window since window is not created yet.
// loading embedded asset:
const webview = new Webview(appWindow, 'theUniqueLabel', {
url: 'path/to/page.html',
// create a webview with specific logical position and size
x: 0,
y: 0,
width: 800,
height: 600,
});
// alternatively, load a remote URL:
const webview = new Webview(appWindow, 'theUniqueLabel', {
url: 'https://github.com/tauri-apps/tauri',
// create a webview with specific logical position and size
x: 0,
y: 0,
width: 800,
height: 600,
});
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();
});

2.0.0

new WebviewWindow(label, options): WebviewWindow

Creates a new Window hosting a Webview.

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

WebviewWindow

The WebviewWindow instance to communicate with the window and webview.

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
});

Window.constructor

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

PropertyTypeDescriptionInherited fromDefined in
labelstringThe webview label. It is a unique identifier for the webview, can be used to reference it later.Window.labelSource: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/webviewWindow.ts#L51
listenersRecord<string, EventCallback<any>[]>Local event listeners.Window.listenersSource: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/webviewWindow.ts#L54
windowWindowThe window hosting this webview.Webview.windowSource: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/webview.ts#L156

center(): Promise<void>

Centers the window.

Promise<void>

A promise indicating the success or failure of the operation.

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

Window.center

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

clearAllBrowsingData(): Promise<void>

Clears all browsing data for this webview.

Promise<void>

A promise indicating the success or failure of the operation.

import { getCurrentWebview } from '@tauri-apps/api/webview';
await getCurrentWebview().clearAllBrowsingData();

Webview.clearAllBrowsingData

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

clearEffects(): Promise<void>

Clear any applied effects if possible.

Promise<void>

Window.clearEffects

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

close(): Promise<void>

Closes the webview.

Promise<void>

A promise indicating the success or failure of the operation.

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

Window.close

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

destroy(): Promise<void>

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

Promise<void>

A promise indicating the success or failure of the operation.

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

Window.destroy

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

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

Emits an event to all targets.

Type Parameter
T
ParameterTypeDescription
eventstringEvent name. Must include only alphanumeric characters, -, /, : and _.
payload?TEvent payload.

Promise<void>

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

Window.emit

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

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

Emits an event to all targets matching the given target.

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

Promise<void>

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

Window.emitTo

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

hide(): Promise<void>

Hide the webview.

Promise<void>

A promise indicating the success or failure of the operation.

import { getCurrentWebview } from '@tauri-apps/api/webview';
await getCurrentWebview().hide();

Window.hide

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

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.

Promise<PhysicalPosition>

The window’s inner position.

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

Window.innerPosition

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

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.

Promise<PhysicalSize>

The window’s inner size.

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

Window.innerSize

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

isAlwaysOnTop(): Promise<boolean>

Whether the window is configured to be always on top of other windows or not.

Promise<boolean>

Whether the window is visible or not.

import { getCurrentWindow } from '@tauri-apps/api/window';
const alwaysOnTop = await getCurrentWindow().isAlwaysOnTop();

Window.isAlwaysOnTop

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

isClosable(): Promise<boolean>

Gets the window’s native close button state.

  • iOS / Android: Unsupported.

Promise<boolean>

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

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

Window.isClosable

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

isDecorated(): Promise<boolean>

Gets the window’s current decorated state.

Promise<boolean>

Whether the window is decorated or not.

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

Window.isDecorated

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

isEnabled(): Promise<boolean>

Whether the window is enabled or disabled.

Promise<boolean>

A promise indicating the success or failure of the operation.

import { getCurrentWindow } from '@tauri-apps/api/window';
await getCurrentWindow().setEnabled(false);

2.0.0

Window.isEnabled

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

isFocused(): Promise<boolean>

Gets the window’s current focus state.

Promise<boolean>

Whether the window is focused or not.

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

Window.isFocused

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

isFullscreen(): Promise<boolean>

Gets the window’s current fullscreen state.

Promise<boolean>

Whether the window is in fullscreen mode or not.

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

Window.isFullscreen

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

isMaximizable(): Promise<boolean>

Gets the window’s native maximize button state.

  • Linux / iOS / Android: Unsupported.

Promise<boolean>

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

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

Window.isMaximizable

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

isMaximized(): Promise<boolean>

Gets the window’s current maximized state.

Promise<boolean>

Whether the window is maximized or not.

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

Window.isMaximized

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

isMinimizable(): Promise<boolean>

Gets the window’s native minimize button state.

  • Linux / iOS / Android: Unsupported.

Promise<boolean>

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

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

Window.isMinimizable

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

isMinimized(): Promise<boolean>

Gets the window’s current minimized state.

Promise<boolean>

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

Window.isMinimized

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

isResizable(): Promise<boolean>

Gets the window’s current resizable state.

Promise<boolean>

Whether the window is resizable or not.

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

Window.isResizable

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

isVisible(): Promise<boolean>

Gets the window’s current visible state.

Promise<boolean>

Whether the window is visible or not.

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

Window.isVisible

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

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

Listen to an emitted event on this webivew window.

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

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.

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();

Window.listen

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

maximize(): Promise<void>

Maximizes the window.

Promise<void>

A promise indicating the success or failure of the operation.

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

Window.maximize

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

minimize(): Promise<void>

Minimizes the window.

Promise<void>

A promise indicating the success or failure of the operation.

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

Window.minimize

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

onCloseRequested(handler): Promise<UnlistenFn>

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

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

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.

import { getCurrentWindow } from "@tauri-apps/api/window";
import { confirm } from '@tauri-apps/api/dialog';
const unlisten = await getCurrentWindow().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();

Window.onCloseRequested

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

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.

ParameterType
handlerEventCallback<DragDropEvent>

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.

import { getCurrentWebview } from "@tauri-apps/api/webview";
const unlisten = await getCurrentWebview().onDragDropEvent((event) => {
if (event.payload.type === 'over') {
console.log('User hovering', event.payload.position);
} 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();

When the debugger panel is open, the drop position of this event may be inaccurate due to a known limitation. To retrieve the correct drop position, please detach the debugger.

Window.onDragDropEvent

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

onFocusChanged(handler): Promise<UnlistenFn>

Listen to window focus change.

ParameterType
handlerEventCallback<boolean>

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.

import { getCurrentWindow } from "@tauri-apps/api/window";
const unlisten = await getCurrentWindow().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();

Window.onFocusChanged

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

onMoved(handler): Promise<UnlistenFn>

Listen to window move.

ParameterType
handlerEventCallback<PhysicalPosition>

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.

import { getCurrentWindow } from "@tauri-apps/api/window";
const unlisten = await getCurrentWindow().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();

Window.onMoved

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

onResized(handler): Promise<UnlistenFn>

Listen to window resize.

ParameterType
handlerEventCallback<PhysicalSize>

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.

import { getCurrentWindow } from "@tauri-apps/api/window";
const unlisten = await getCurrentWindow().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();

Window.onResized

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

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.
ParameterType
handlerEventCallback<ScaleFactorChanged>

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.

import { getCurrentWindow } from "@tauri-apps/api/window";
const unlisten = await getCurrentWindow().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();

Window.onScaleChanged

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

onThemeChanged(handler): Promise<UnlistenFn>

Listen to the system theme change.

ParameterType
handlerEventCallback<Theme>

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.

import { getCurrentWindow } from "@tauri-apps/api/window";
const unlisten = await getCurrentWindow().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();

Window.onThemeChanged

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

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

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

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

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.

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();

Window.once

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

outerPosition(): Promise<PhysicalPosition>

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

Promise<PhysicalPosition>

The window’s outer position.

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

Window.outerPosition

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

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.

Promise<PhysicalSize>

The window’s outer size.

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

Window.outerSize

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

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.

Promise<PhysicalPosition>

The webview’s position.

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

Webview.position

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

reparent(window): Promise<void>

Moves this webview to the given label.

ParameterType
windowstring | Window | WebviewWindow

Promise<void>

A promise indicating the success or failure of the operation.

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

Webview.reparent

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

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.

  • macOS: null has no effect.
  • Linux: Urgency levels have the same effect.
ParameterType
requestTypenull | UserAttentionType

Promise<void>

A promise indicating the success or failure of the operation.

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

Window.requestUserAttention

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

scaleFactor(): Promise<number>

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

Promise<number>

The window’s monitor scale factor.

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

Window.scaleFactor

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

setAlwaysOnBottom(alwaysOnBottom): Promise<void>

Whether the window should always be below other windows.

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

Promise<void>

A promise indicating the success or failure of the operation.

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

Window.setAlwaysOnBottom

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

setAlwaysOnTop(alwaysOnTop): Promise<void>

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

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

Promise<void>

A promise indicating the success or failure of the operation.

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

Window.setAlwaysOnTop

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

setAutoResize(autoResize): Promise<void>

Sets whether the webview should automatically grow and shrink its size and position when the parent window resizes.

ParameterType
autoResizeboolean

Promise<void>

A promise indicating the success or failure of the operation.

import { getCurrentWebview } from '@tauri-apps/api/webview';
await getCurrentWebview().setAutoResize(true);

Webview.setAutoResize

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

setBackgroundColor(color): Promise<void>

Set the window and webview background color.

  • Android / iOS: Unsupported for the window layer.
  • macOS / iOS: Not implemented for the webview layer.
  • Windows:
    • alpha channel is ignored for the window layer.
    • On Windows 7, alpha channel is ignored for the webview layer.
    • On Windows 8 and newer, if alpha channel is not 0, it will be ignored.
ParameterType
colorColor

Promise<void>

A promise indicating the success or failure of the operation.

2.1.0

Window.setBackgroundColor

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

setBadgeCount(count?): Promise<void>

Sets the badge count. It is app wide and not specific to this window.

  • Windows: Unsupported. Use @{linkcode Window.setOverlayIcon} instead.
ParameterTypeDescription
count?numberThe badge count. Use undefined to remove the badge.

Promise<void>

A promise indicating the success or failure of the operation.

import { getCurrentWindow } from '@tauri-apps/api/window';
await getCurrentWindow().setBadgeCount(5);

Window.setBadgeCount

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

setBadgeLabel(label?): Promise<void>

Sets the badge cont macOS only.

ParameterTypeDescription
label?stringThe badge label. Use undefined to remove the badge.

Promise<void>

A promise indicating the success or failure of the operation.

import { getCurrentWindow } from '@tauri-apps/api/window';
await getCurrentWindow().setBadgeLabel("Hello");

Window.setBadgeLabel

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

setClosable(closable): Promise<void>

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

  • 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.
ParameterType
closableboolean

Promise<void>

A promise indicating the success or failure of the operation.

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

Window.setClosable

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

setContentProtected(protected_): Promise<void>

Prevents the window contents from being captured by other apps.

ParameterType
protected_boolean

Promise<void>

A promise indicating the success or failure of the operation.

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

Window.setContentProtected

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

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.

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

Promise<void>

A promise indicating the success or failure of the operation.

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

Window.setCursorGrab

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

setCursorIcon(icon): Promise<void>

Modifies the cursor icon of the window.

ParameterTypeDescription
iconCursorIconThe new cursor icon.

Promise<void>

A promise indicating the success or failure of the operation.

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

Window.setCursorIcon

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

setCursorPosition(position): Promise<void>

Changes the position of the cursor in window coordinates.

ParameterTypeDescription
positionLogicalPosition | PhysicalPosition | PositionThe new cursor position.

Promise<void>

A promise indicating the success or failure of the operation.

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

Window.setCursorPosition

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

setCursorVisible(visible): Promise<void>

Modifies the cursor’s visibility.

  • 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.
ParameterTypeDescription
visiblebooleanIf false, this will hide the cursor. If true, this will show the cursor.

Promise<void>

A promise indicating the success or failure of the operation.

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

Window.setCursorVisible

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

setDecorations(decorations): Promise<void>

Whether the window should have borders and bars.

ParameterTypeDescription
decorationsbooleanWhether the window should have borders and bars.

Promise<void>

A promise indicating the success or failure of the operation.

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

Window.setDecorations

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

setEffects(effects): Promise<void>

Set window effects.

ParameterType
effectsEffects

Promise<void>

Window.setEffects

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

setEnabled(enabled): Promise<void>

Enable or disable the window.

ParameterType
enabledboolean

Promise<void>

A promise indicating the success or failure of the operation.

import { getCurrentWindow } from '@tauri-apps/api/window';
await getCurrentWindow().setEnabled(false);

2.0.0

Window.setEnabled

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

setFocus(): Promise<void>

Bring the webview to front and focus.

Promise<void>

A promise indicating the success or failure of the operation.

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

Window.setFocus

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

setFullscreen(fullscreen): Promise<void>

Sets the window fullscreen state.

ParameterTypeDescription
fullscreenbooleanWhether the window should go to fullscreen or not.

Promise<void>

A promise indicating the success or failure of the operation.

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

Window.setFullscreen

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

setIcon(icon): Promise<void>

Sets the window icon.

ParameterTypeDescription
icon| string | number[] | ArrayBuffer | Uint8Array<ArrayBufferLike> | ImageIcon bytes or path to the icon file.

Promise<void>

A promise indicating the success or failure of the operation.

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

Note that you may 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"] }

Window.setIcon

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

setIgnoreCursorEvents(ignore): Promise<void>

Changes the cursor events behavior.

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

Promise<void>

A promise indicating the success or failure of the operation.

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

Window.setIgnoreCursorEvents

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

setMaxSize(size): Promise<void>

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

ParameterTypeDescription
size| undefined | null | LogicalSize | PhysicalSize | SizeThe logical or physical inner size, or null to unset the constraint.

Promise<void>

A promise indicating the success or failure of the operation.

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

Window.setMaxSize

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

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.

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

Promise<void>

A promise indicating the success or failure of the operation.

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

Window.setMaximizable

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

setMinSize(size): Promise<void>

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

ParameterTypeDescription
size| undefined | null | LogicalSize | PhysicalSize | SizeThe logical or physical inner size, or null to unset the constraint.

Promise<void>

A promise indicating the success or failure of the operation.

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

Window.setMinSize

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

setMinimizable(minimizable): Promise<void>

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

  • Linux / iOS / Android: Unsupported.
ParameterType
minimizableboolean

Promise<void>

A promise indicating the success or failure of the operation.

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

Window.setMinimizable

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

setOverlayIcon(icon?): Promise<void>

Sets the overlay icon. Windows only The overlay icon can be set for every window.

Note that you may 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"] }
ParameterTypeDescription
icon?| string | number[] | ArrayBuffer | Uint8Array<ArrayBufferLike> | ImageIcon bytes or path to the icon file. Use undefined to remove the overlay icon.

Promise<void>

A promise indicating the success or failure of the operation.

import { getCurrentWindow } from '@tauri-apps/api/window';
await getCurrentWindow().setOverlayIcon("/tauri/awesome.png");

Window.setOverlayIcon

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

setPosition(position): Promise<void>

Sets the webview position.

ParameterTypeDescription
positionLogicalPosition | PhysicalPosition | PositionThe new position, in logical or physical pixels.

Promise<void>

A promise indicating the success or failure of the operation.

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

Window.setPosition

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

setProgressBar(state): Promise<void>

Sets the taskbar progress state.

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

Promise<void>

A promise indicating the success or failure of the operation.

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

Window.setProgressBar

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

setResizable(resizable): Promise<void>

Updates the window resizable flag.

ParameterType
resizableboolean

Promise<void>

A promise indicating the success or failure of the operation.

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

Window.setResizable

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

setShadow(enable): Promise<void>

Whether or not the window should have shadow.

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

Promise<void>

A promise indicating the success or failure of the operation.

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

Window.setShadow

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

setSize(size): Promise<void>

Resizes the webview.

ParameterTypeDescription
sizeLogicalSize | PhysicalSize | SizeThe logical or physical size.

Promise<void>

A promise indicating the success or failure of the operation.

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

Window.setSize

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

setSizeConstraints(constraints): Promise<void>

Sets the window inner size constraints.

ParameterTypeDescription
constraintsundefined | null | WindowSizeConstraintsThe logical or physical inner size, or null to unset the constraint.

Promise<void>

A promise indicating the success or failure of the operation.

import { getCurrentWindow } from '@tauri-apps/api/window';
await getCurrentWindow().setSizeConstraints({ minWidth: 300 });

Window.setSizeConstraints

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

setSkipTaskbar(skip): Promise<void>

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

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

Promise<void>

A promise indicating the success or failure of the operation.

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

Window.setSkipTaskbar

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

setTheme(theme?): Promise<void>

Set window theme, pass in null or undefined to follow system theme

  • Linux / macOS: Theme is app-wide and not specific to this window.
  • iOS / Android: Unsupported.
ParameterType
theme?null | Theme

Promise<void>

2.0.0

Window.setTheme

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

setTitle(title): Promise<void>

Sets the window title.

ParameterTypeDescription
titlestringThe new title

Promise<void>

A promise indicating the success or failure of the operation.

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

Window.setTitle

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

setTitleBarStyle(style): Promise<void>

Sets the title bar style. macOS only.

ParameterType
styleTitleBarStyle

Promise<void>

2.0.0

Window.setTitleBarStyle

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

setVisibleOnAllWorkspaces(visible): Promise<void>

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

  • Windows / iOS / Android: Unsupported.
ParameterType
visibleboolean

Promise<void>

2.0.0

Window.setVisibleOnAllWorkspaces

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

setZoom(scaleFactor): Promise<void>

Set webview zoom level.

ParameterType
scaleFactornumber

Promise<void>

A promise indicating the success or failure of the operation.

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

Webview.setZoom

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

show(): Promise<void>

Show the webview.

Promise<void>

A promise indicating the success or failure of the operation.

import { getCurrentWebview } from '@tauri-apps/api/webview';
await getCurrentWebview().show();

Window.show

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

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.

Promise<PhysicalSize>

The webview’s size.

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

Webview.size

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

startDragging(): Promise<void>

Starts dragging the window.

Promise<void>

A promise indicating the success or failure of the operation.

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

Window.startDragging

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

startResizeDragging(direction): Promise<void>

Starts resize-dragging the window.

ParameterType
directionResizeDirection

Promise<void>

A promise indicating the success or failure of the operation.

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

Window.startResizeDragging

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

theme(): Promise<null | Theme>

Gets the window’s current theme.

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

Promise<null | Theme>

The window theme.

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

Window.theme

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

title(): Promise<string>

Gets the window’s current title.

Promise<string>

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

Window.title

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

toggleMaximize(): Promise<void>

Toggles the window maximized state.

Promise<void>

A promise indicating the success or failure of the operation.

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

Window.toggleMaximize

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

unmaximize(): Promise<void>

Unmaximizes the window.

Promise<void>

A promise indicating the success or failure of the operation.

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

Window.unmaximize

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

unminimize(): Promise<void>

Unminimizes the window.

Promise<void>

A promise indicating the success or failure of the operation.

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

Window.unminimize

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

static getAll(): Promise<WebviewWindow[]>

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

Promise<WebviewWindow[]>

Window.getAll

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

static getByLabel(label): Promise<null | WebviewWindow>

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

ParameterTypeDescription
labelstringThe webview label.

Promise<null | WebviewWindow>

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

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

Window.getByLabel

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

static getCurrent(): WebviewWindow

Get an instance of Webview for the current webview.

WebviewWindow

Window.getCurrent

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

function getAllWebviewWindows(): Promise<WebviewWindow[]>

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

Promise<WebviewWindow[]>

2.0.0

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


function getCurrentWebviewWindow(): WebviewWindow

Get an instance of Webview for the current webview window.

WebviewWindow

2.0.0

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


© 2025 Tauri Contributors. CC-BY / MIT