Skip to content

@tauri-apps/api/webviewWindow

function getAllWebviewWindows(): Promise<WebviewWindow[]>;

Defined in: packages/api/src/webviewWindow.ts:34

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

Promise<WebviewWindow[]>

2.0.0


function getCurrentWebviewWindow(): WebviewWindow;

Defined in: packages/api/src/webviewWindow.ts:23

Get an instance of Webview for the current webview window.

WebviewWindow

2.0.0

Defined in: packages/api/src/webviewWindow.ts:47

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: string, options?: Omit<WebviewOptions, "x" | "y" | "width" | "height"> & WindowOptions): WebviewWindow;

Defined in: packages/api/src/webviewWindow.ts:75

Creates a new Window hosting a 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
});
Parameter Type Description
label string The unique webview label. Must be alphanumeric: a-zA-Z-/:_.
options Omit<WebviewOptions, "x" | "y" | "width" | "height"> & WindowOptions -

WebviewWindow

The WebviewWindow instance to communicate with the window and webview.

Webview.constructor

Property Type Description Inherited from Defined in
label string The webview label. It is a unique identifier for the webview, can be used to reference it later. Webview.label packages/api/src/webviewWindow.ts:51
listeners Record<string, EventCallback<any>[]> Local event listeners. Webview.listeners packages/api/src/webviewWindow.ts:54
window Window The window hosting this webview. Webview.window packages/api/src/webview.ts:157

activityName(): Promise<string>;

Defined in: packages/api/src/window.ts:853

Promise<string>

Window.activityName

center(): Promise<void>;

Defined in: packages/api/src/window.ts:877

Centers the window.

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

Promise<void>

A promise indicating the success or failure of the operation.

Window.center

clearAllBrowsingData(): Promise<void>;

Defined in: packages/api/src/webview.ts:589

Clears all browsing data for this webview.

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

Promise<void>

A promise indicating the success or failure of the operation.

Webview.clearAllBrowsingData

clearEffects(): Promise<void>;

Defined in: packages/api/src/window.ts:1265

Clear any applied effects if possible.

Promise<void>

Window.clearEffects

close(): Promise<void>;

Defined in: packages/api/src/webview.ts:436

Closes the webview.

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

Promise<void>

A promise indicating the success or failure of the operation.

Webview.close

destroy(): Promise<void>;

Defined in: packages/api/src/window.ts:1202

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

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

Promise<void>

A promise indicating the success or failure of the operation.

Window.destroy

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

Defined in: packages/api/src/webview.ts:325

Emits an event to all targets.

import { getCurrentWebview } from '@tauri-apps/api/webview';
await getCurrentWebview().emit('webview-loaded', { loggedIn: true, token: 'authToken' });
Type Parameter
T
Parameter Type Description
event string Event name. Must include only alphanumeric characters, -, /, : and _.
payload? T Event payload.

Promise<void>

Webview.emit

emitTo<T>(
target: string | EventTarget,
event: string,
payload?: T): Promise<void>;

Defined in: packages/api/src/webview.ts:353

Emits an event to all targets matching the given target.

import { getCurrentWebview } from '@tauri-apps/api/webview';
await getCurrentWebview().emitTo('main', 'webview-loaded', { loggedIn: true, token: 'authToken' });
Type Parameter
T
Parameter Type Description
target | string | EventTarget Label of the target Window/Webview/WebviewWindow or raw EventTarget object.
event string Event name. Must include only alphanumeric characters, -, /, : and _.
payload? T Event payload.

Promise<void>

Webview.emitTo

hide(): Promise<void>;

Defined in: packages/api/src/webview.ts:523

Hide the webview.

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

Promise<void>

A promise indicating the success or failure of the operation.

Webview.hide

innerPosition(): Promise<PhysicalPosition>;

Defined in: packages/api/src/window.ts:567

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

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

Promise<PhysicalPosition>

The window’s inner position.

Window.innerPosition

innerSize(): Promise<PhysicalSize>;

Defined in: packages/api/src/window.ts:600

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

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

Promise<PhysicalSize>

The window’s inner size.

Window.innerSize

isAlwaysOnTop(): Promise<boolean>;

Defined in: packages/api/src/window.ts:847

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

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

Promise<boolean>

Whether the window is visible or not.

Window.isAlwaysOnTop

isClosable(): Promise<boolean>;

Defined in: packages/api/src/window.ts:780

Gets the window’s native close button state.

Platform-specific

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

Promise<boolean>

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

Window.isClosable

isDecorated(): Promise<boolean>;

Defined in: packages/api/src/window.ts:701

Gets the window’s current decorated state.

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

Promise<boolean>

Whether the window is decorated or not.

Window.isDecorated

isEnabled(): Promise<boolean>;

Defined in: packages/api/src/window.ts:969

Whether the window is enabled or disabled.

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

Promise<boolean>

A promise indicating the success or failure of the operation.

2.0.0

Window.isEnabled

isFocused(): Promise<boolean>;

Defined in: packages/api/src/window.ts:685

Gets the window’s current focus state.

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

Promise<boolean>

Whether the window is focused or not.

Window.isFocused

isFullscreen(): Promise<boolean>;

Defined in: packages/api/src/window.ts:639

Gets the window’s current fullscreen state.

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

Promise<boolean>

Whether the window is in fullscreen mode or not.

Window.isFullscreen

isMaximizable(): Promise<boolean>;

Defined in: packages/api/src/window.ts:738

Gets the window’s native maximize button state.

Platform-specific

  • Linux / iOS / Android: Unsupported.
import { getCurrentWindow } from '@tauri-apps/api/window';
const maximizable = await getCurrentWindow().isMaximizable();

Promise<boolean>

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

Window.isMaximizable

isMaximized(): Promise<boolean>;

Defined in: packages/api/src/window.ts:669

Gets the window’s current maximized state.

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

Promise<boolean>

Whether the window is maximized or not.

Window.isMaximized

isMinimizable(): Promise<boolean>;

Defined in: packages/api/src/window.ts:759

Gets the window’s native minimize button state.

Platform-specific

  • Linux / iOS / Android: Unsupported.
import { getCurrentWindow } from '@tauri-apps/api/window';
const minimizable = await getCurrentWindow().isMinimizable();

Promise<boolean>

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

Window.isMinimizable

isMinimized(): Promise<boolean>;

Defined in: packages/api/src/window.ts:653

Gets the window’s current minimized state.

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

Promise<boolean>

Window.isMinimized

isResizable(): Promise<boolean>;

Defined in: packages/api/src/window.ts:717

Gets the window’s current resizable state.

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

Promise<boolean>

Whether the window is resizable or not.

Window.isResizable

isVisible(): Promise<boolean>;

Defined in: packages/api/src/window.ts:796

Gets the window’s current visible state.

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

Promise<boolean>

Whether the window is visible or not.

Window.isVisible

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

Defined in: packages/api/src/webviewWindow.ts:155

Listen to an emitted event on this webview window.

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();
Type Parameter
T
Parameter Type Description
event EventName Event name. Must include only alphanumeric characters, -, /, : and _.
handler EventCallback<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.

Webview.listen

maximize(): Promise<void>;

Defined in: packages/api/src/window.ts:1072

Maximizes the window.

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

Promise<void>

A promise indicating the success or failure of the operation.

Window.maximize

minimize(): Promise<void>;

Defined in: packages/api/src/window.ts:1120

Minimizes the window.

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

Promise<void>

A promise indicating the success or failure of the operation.

Window.minimize

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

Defined in: packages/api/src/webviewWindow.ts:190

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

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();
Type Parameter
T
Parameter Type Description
event EventName Event name. Must include only alphanumeric characters, -, /, : and _.
handler EventCallback<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.

Webview.once

onCloseRequested(handler: (event: CloseRequestedEvent) =>
| void
| Promise<void>): Promise<UnlistenFn>;

Defined in: packages/api/src/window.ts:1927

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

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();
Parameter Type
handler (event: CloseRequestedEvent) => | 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.

Window.onCloseRequested

onDragDropEvent(handler: EventCallback<DragDropEvent>): Promise<UnlistenFn>;

Defined in: packages/api/src/webview.ts:641

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.

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.

Parameter Type
handler EventCallback<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.

Webview.onDragDropEvent

onFocusChanged(handler: EventCallback<boolean>): Promise<UnlistenFn>;

Defined in: packages/api/src/window.ts:2043

Listen to window focus change.

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();
Parameter Type
handler EventCallback<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.

Window.onFocusChanged

onMoved(handler: EventCallback<PhysicalPosition>): Promise<UnlistenFn>;

Defined in: packages/api/src/window.ts:1898

Listen to window move.

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();
Parameter Type
handler EventCallback<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.

Window.onMoved

onResized(handler: EventCallback<PhysicalSize>): Promise<UnlistenFn>;

Defined in: packages/api/src/window.ts:1874

Listen to window resize.

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();
Parameter Type
handler EventCallback<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.

Window.onResized

onScaleChanged(handler: EventCallback<ScaleFactorChanged>): Promise<UnlistenFn>;

Defined in: packages/api/src/window.ts:2083

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.
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();
Parameter Type
handler EventCallback<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.

Window.onScaleChanged

onThemeChanged(handler: EventCallback<Theme>): Promise<UnlistenFn>;

Defined in: packages/api/src/window.ts:2109

Listen to the system theme change.

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();
Parameter Type
handler EventCallback<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.

Window.onThemeChanged

outerPosition(): Promise<PhysicalPosition>;

Defined in: packages/api/src/window.ts:583

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

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

Promise<PhysicalPosition>

The window’s outer position.

Window.outerPosition

outerSize(): Promise<PhysicalSize>;

Defined in: packages/api/src/window.ts:620

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.

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

Promise<PhysicalSize>

The window’s outer size.

Window.outerSize

position(): Promise<PhysicalPosition>;

Defined in: packages/api/src/webview.ts:398

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

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

Promise<PhysicalPosition>

The webview’s position.

Webview.position

reparent(window: string | Window | WebviewWindow): Promise<void>;

Defined in: packages/api/src/webview.ts:572

Moves this webview to the given label.

import { getCurrentWebview } from '@tauri-apps/api/webview';
await getCurrentWebview().reparent('other-window');
Parameter Type
window | string | Window | WebviewWindow

Promise<void>

A promise indicating the success or failure of the operation.

Webview.reparent

requestUserAttention(requestType: UserAttentionType | null): Promise<void>;

Defined in: packages/api/src/window.ts:903

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.
import { getCurrentWindow } from '@tauri-apps/api/window';
await getCurrentWindow().requestUserAttention();
Parameter Type
requestType | UserAttentionType | null

Promise<void>

A promise indicating the success or failure of the operation.

Window.requestUserAttention

scaleFactor(): Promise<number>;

Defined in: packages/api/src/window.ts:551

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

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

Promise<number>

The window’s monitor scale factor.

Window.scaleFactor

sceneIdentifier(): Promise<string>;

Defined in: packages/api/src/window.ts:859

Promise<string>

Window.sceneIdentifier

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

Defined in: packages/api/src/window.ts:1301

Whether the window should always be below other windows.

import { getCurrentWindow } from '@tauri-apps/api/window';
await getCurrentWindow().setAlwaysOnBottom(true);
Parameter Type Description
alwaysOnBottom boolean Whether the window should always be below other windows or not.

Promise<void>

A promise indicating the success or failure of the operation.

Window.setAlwaysOnBottom

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

Defined in: packages/api/src/window.ts:1283

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

import { getCurrentWindow } from '@tauri-apps/api/window';
await getCurrentWindow().setAlwaysOnTop(true);
Parameter Type Description
alwaysOnTop boolean Whether the window should always be on top of other windows or not.

Promise<void>

A promise indicating the success or failure of the operation.

Window.setAlwaysOnTop

setAutoResize(autoResize: boolean): Promise<void>;

Defined in: packages/api/src/webview.ts:506

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

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

Promise<void>

A promise indicating the success or failure of the operation.

Webview.setAutoResize

setBackgroundColor(color: Color): Promise<void>;

Defined in: packages/api/src/webviewWindow.ts:222

Set the window and webview background color.

Platform-specific

  • 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.
Parameter Type
color Color

Promise<void>

A promise indicating the success or failure of the operation.

2.1.0

Webview.setBackgroundColor

setBadgeCount(count?: number): Promise<void>;

Defined in: packages/api/src/window.ts:1727

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

Platform-specific

  • Windows: Unsupported. Use @{linkcode Window.setOverlayIcon} instead.
import { getCurrentWindow } from '@tauri-apps/api/window';
await getCurrentWindow().setBadgeCount(5);
Parameter Type Description
count? number The badge count. Use undefined to remove the badge.

Promise<void>

A promise indicating the success or failure of the operation.

Window.setBadgeCount

setBadgeLabel(label?: string): Promise<void>;

Defined in: packages/api/src/window.ts:1746

Sets the badge cont macOS only.

import { getCurrentWindow } from '@tauri-apps/api/window';
await getCurrentWindow().setBadgeLabel("Hello");
Parameter Type Description
label? string The badge label. Use undefined to remove the badge.

Promise<void>

A promise indicating the success or failure of the operation.

Window.setBadgeLabel

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

Defined in: packages/api/src/window.ts:1037

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.
import { getCurrentWindow } from '@tauri-apps/api/window';
await getCurrentWindow().setClosable(false);
Parameter Type
closable boolean

Promise<void>

A promise indicating the success or failure of the operation.

Window.setClosable

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

Defined in: packages/api/src/window.ts:1318

Prevents the window contents from being captured by other apps.

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

Promise<void>

A promise indicating the success or failure of the operation.

Window.setContentProtected

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

Defined in: packages/api/src/window.ts:1574

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.
import { getCurrentWindow } from '@tauri-apps/api/window';
await getCurrentWindow().setCursorGrab(true);
Parameter Type Description
grab boolean true to grab the cursor icon, false to release it.

Promise<void>

A promise indicating the success or failure of the operation.

Window.setCursorGrab

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

Defined in: packages/api/src/window.ts:1616

Modifies the cursor icon of the window.

import { getCurrentWindow } from '@tauri-apps/api/window';
await getCurrentWindow().setCursorIcon('help');
Parameter Type Description
icon CursorIcon The new cursor icon.

Promise<void>

A promise indicating the success or failure of the operation.

Window.setCursorIcon

setCursorPosition(position: PhysicalPosition | LogicalPosition | Position): Promise<void>;

Defined in: packages/api/src/window.ts:1650

Changes the position of the cursor in window coordinates.

import { getCurrentWindow, LogicalPosition } from '@tauri-apps/api/window';
await getCurrentWindow().setCursorPosition(new LogicalPosition(600, 300));
Parameter Type Description
position | PhysicalPosition | LogicalPosition | Position The new cursor position.

Promise<void>

A promise indicating the success or failure of the operation.

Window.setCursorPosition

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

Defined in: packages/api/src/window.ts:1598

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.
import { getCurrentWindow } from '@tauri-apps/api/window';
await getCurrentWindow().setCursorVisible(false);
Parameter Type Description
visible boolean If 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.

Window.setCursorVisible

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

Defined in: packages/api/src/window.ts:1219

Whether the window should have borders and bars.

import { getCurrentWindow } from '@tauri-apps/api/window';
await getCurrentWindow().setDecorations(false);
Parameter Type Description
decorations boolean Whether the window should have borders and bars.

Promise<void>

A promise indicating the success or failure of the operation.

Window.setDecorations

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

Defined in: packages/api/src/window.ts:1255

Set window effects.

Parameter Type
effects Effects

Promise<void>

Window.setEffects

setEnabled(enabled: boolean): Promise<void>;

Defined in: packages/api/src/window.ts:950

Enable or disable the window.

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

Promise<void>

A promise indicating the success or failure of the operation.

2.0.0

Window.setEnabled

setFocus(): Promise<void>;

Defined in: packages/api/src/webview.ts:490

Bring the webview to front and focus.

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

Promise<void>

A promise indicating the success or failure of the operation.

Webview.setFocus

setFocusable(focusable: boolean): Promise<void>;

Defined in: packages/api/src/window.ts:1499

Sets whether the window can be focused.

Platform-specific

  • macOS: If the window is already focused, it is not possible to unfocus it after calling set_focusable(false). In this case, you might consider calling Window.setFocus but it will move the window to the back i.e. at the bottom in terms of z-order.
import { getCurrentWindow } from '@tauri-apps/api/window';
await getCurrentWindow().setFocusable(true);
Parameter Type Description
focusable boolean Whether the window can be focused.

Promise<void>

A promise indicating the success or failure of the operation.

Window.setFocusable

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

Defined in: packages/api/src/window.ts:1443

Sets the window fullscreen state.

import { getCurrentWindow } from '@tauri-apps/api/window';
await getCurrentWindow().setFullscreen(true);
Parameter Type Description
fullscreen boolean Whether the window should go to fullscreen or not.

Promise<void>

A promise indicating the success or failure of the operation.

Window.setFullscreen

setIcon(icon: string | Image | Uint8Array | ArrayBuffer | number[]): Promise<void>;

Defined in: packages/api/src/window.ts:1524

Sets the window icon.

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"] }
Parameter Type Description
icon | string | Image | Uint8Array | ArrayBuffer | number[] Icon bytes or path to the icon file.

Promise<void>

A promise indicating the success or failure of the operation.

Window.setIcon

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

Defined in: packages/api/src/window.ts:1671

Changes the cursor events behavior.

import { getCurrentWindow } from '@tauri-apps/api/window';
await getCurrentWindow().setIgnoreCursorEvents(true);
Parameter Type Description
ignore boolean true to ignore the cursor events; false to process them as usual.

Promise<void>

A promise indicating the success or failure of the operation.

Window.setIgnoreCursorEvents

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

Defined in: packages/api/src/window.ts:992

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.
import { getCurrentWindow } from '@tauri-apps/api/window';
await getCurrentWindow().setMaximizable(false);
Parameter Type
maximizable boolean

Promise<void>

A promise indicating the success or failure of the operation.

Window.setMaximizable

setMaxSize(size: PhysicalSize | LogicalSize | Size | null | undefined): Promise<void>;

Defined in: packages/api/src/window.ts:1374

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

import { getCurrentWindow, LogicalSize } from '@tauri-apps/api/window';
await getCurrentWindow().setMaxSize(new LogicalSize(600, 500));
Parameter Type Description
size | PhysicalSize | LogicalSize | Size | null | undefined The logical or physical inner size, or null to unset the constraint.

Promise<void>

A promise indicating the success or failure of the operation.

Window.setMaxSize

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

Defined in: packages/api/src/window.ts:1014

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

Platform-specific

  • Linux / iOS / Android: Unsupported.
import { getCurrentWindow } from '@tauri-apps/api/window';
await getCurrentWindow().setMinimizable(false);
Parameter Type
minimizable boolean

Promise<void>

A promise indicating the success or failure of the operation.

Window.setMinimizable

setMinSize(size: PhysicalSize | LogicalSize | Size | null | undefined): Promise<void>;

Defined in: packages/api/src/window.ts:1354

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

import { getCurrentWindow, PhysicalSize } from '@tauri-apps/api/window';
await getCurrentWindow().setMinSize(new PhysicalSize(600, 500));
Parameter Type Description
size | PhysicalSize | LogicalSize | Size | null | undefined The logical or physical inner size, or null to unset the constraint.

Promise<void>

A promise indicating the success or failure of the operation.

Window.setMinSize

setOverlayIcon(icon?: string | Image | Uint8Array | ArrayBuffer | number[]): Promise<void>;

Defined in: packages/api/src/window.ts:1775

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"] }
import { getCurrentWindow } from '@tauri-apps/api/window';
await getCurrentWindow().setOverlayIcon("/tauri/awesome.png");
Parameter Type Description
icon? | string | Image | Uint8Array | ArrayBuffer | number[] Icon 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.

Window.setOverlayIcon

setPosition(position: PhysicalPosition | LogicalPosition | Position): Promise<void>;

Defined in: packages/api/src/webview.ts:471

Sets the webview position.

import { getCurrent, LogicalPosition } from '@tauri-apps/api/webview';
await getCurrentWebview().setPosition(new LogicalPosition(600, 500));
Parameter Type Description
position | PhysicalPosition | LogicalPosition | Position The new position, in logical or physical pixels.

Promise<void>

A promise indicating the success or failure of the operation.

Webview.setPosition

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

Defined in: packages/api/src/window.ts:1803

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).
import { getCurrentWindow, ProgressBarStatus } from '@tauri-apps/api/window';
await getCurrentWindow().setProgressBar({
status: ProgressBarStatus.Normal,
progress: 50,
});
Parameter Type
state ProgressBarState

Promise<void>

A promise indicating the success or failure of the operation.

Window.setProgressBar

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

Defined in: packages/api/src/window.ts:931

Updates the window resizable flag.

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

Promise<void>

A promise indicating the success or failure of the operation.

Window.setResizable

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

Defined in: packages/api/src/window.ts:1245

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 undecorated window have a 1px white border, and on Windows 11, it will have a rounded corners.
  • Linux: Unsupported.
import { getCurrentWindow } from '@tauri-apps/api/window';
await getCurrentWindow().setShadow(false);
Parameter Type
enable boolean

Promise<void>

A promise indicating the success or failure of the operation.

Window.setShadow

setSimpleFullscreen(fullscreen: boolean): Promise<void>;

Defined in: packages/api/src/window.ts:1459

On macOS, Toggles a fullscreen mode that doesn’t require a new macOS space. Returns a boolean indicating whether the transition was successful (this won’t work if the window was already in the native fullscreen). This is how fullscreen used to work on macOS in versions before Lion. And allows the user to have a fullscreen window without using another space or taking control over the entire monitor.

On other platforms, this is the same as Window.setFullscreen.

Parameter Type Description
fullscreen boolean Whether the window should go to simple fullscreen or not.

Promise<void>

A promise indicating the success or failure of the operation.

Window.setSimpleFullscreen

setSize(size: PhysicalSize | LogicalSize | Size): Promise<void>;

Defined in: packages/api/src/webview.ts:453

Resizes the webview.

import { getCurrent, LogicalSize } from '@tauri-apps/api/webview';
await getCurrentWebview().setSize(new LogicalSize(600, 500));
Parameter Type Description
size | PhysicalSize | LogicalSize | Size The logical or physical size.

Promise<void>

A promise indicating the success or failure of the operation.

Webview.setSize

setSizeConstraints(constraints: WindowSizeConstraints | null | undefined): Promise<void>;

Defined in: packages/api/src/window.ts:1394

Sets the window inner size constraints.

import { getCurrentWindow } from '@tauri-apps/api/window';
await getCurrentWindow().setSizeConstraints({ minWidth: 300 });
Parameter Type Description
constraints | WindowSizeConstraints | null | undefined The logical or physical inner size, or null to unset the constraint.

Promise<void>

A promise indicating the success or failure of the operation.

Window.setSizeConstraints

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

Defined in: packages/api/src/window.ts:1548

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

Platform-specific

  • macOS: Unsupported.
import { getCurrentWindow } from '@tauri-apps/api/window';
await getCurrentWindow().setSkipTaskbar(true);
Parameter Type Description
skip boolean true to hide window icon, false to show it.

Promise<void>

A promise indicating the success or failure of the operation.

Window.setSkipTaskbar

setTheme(theme?: Theme | null): Promise<void>;

Defined in: packages/api/src/window.ts:1848

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

Platform-specific

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

Promise<void>

2.0.0

Window.setTheme

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

Defined in: packages/api/src/window.ts:1055

Sets the window title.

import { getCurrentWindow } from '@tauri-apps/api/window';
await getCurrentWindow().setTitle('Tauri');
Parameter Type Description
title string The new title

Promise<void>

A promise indicating the success or failure of the operation.

Window.setTitle

setTitleBarStyle(style: TitleBarStyle): Promise<void>;

Defined in: packages/api/src/window.ts:1831

Sets the title bar style. macOS only.

Parameter Type
style TitleBarStyle

Promise<void>

2.0.0

Window.setTitleBarStyle

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

Defined in: packages/api/src/window.ts:1819

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

Platform-specific

  • Windows / iOS / Android: Unsupported.
Parameter Type
visible boolean

Promise<void>

2.0.0

Window.setVisibleOnAllWorkspaces

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

Defined in: packages/api/src/webview.ts:555

Set webview zoom level.

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

Promise<void>

A promise indicating the success or failure of the operation.

Webview.setZoom

show(): Promise<void>;

Defined in: packages/api/src/webview.ts:539

Show the webview.

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

Promise<void>

A promise indicating the success or failure of the operation.

Webview.show

size(): Promise<PhysicalSize>;

Defined in: packages/api/src/webview.ts:415

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

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

Promise<PhysicalSize>

The webview’s size.

Webview.size

startDragging(): Promise<void>;

Defined in: packages/api/src/window.ts:1688

Starts dragging the window.

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

Promise<void>

A promise indicating the success or failure of the operation.

Window.startDragging

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

Defined in: packages/api/src/window.ts:1704

Starts resize-dragging the window.

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

Promise<void>

A promise indicating the success or failure of the operation.

Window.startResizeDragging

theme(): Promise<Theme | null>;

Defined in: packages/api/src/window.ts:831

Gets the window’s current theme.

Platform-specific

  • macOS: Theme was introduced on macOS 10.14. Returns light on macOS 10.13 and below.
import { getCurrentWindow } from '@tauri-apps/api/window';
const theme = await getCurrentWindow().theme();

Promise<Theme | null>

The window theme.

Window.theme

title(): Promise<string>;

Defined in: packages/api/src/window.ts:810

Gets the window’s current title.

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

Promise<string>

Window.title

toggleMaximize(): Promise<void>;

Defined in: packages/api/src/window.ts:1104

Toggles the window maximized state.

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

Promise<void>

A promise indicating the success or failure of the operation.

Window.toggleMaximize

unmaximize(): Promise<void>;

Defined in: packages/api/src/window.ts:1088

Unmaximizes the window.

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

Promise<void>

A promise indicating the success or failure of the operation.

Window.unmaximize

unminimize(): Promise<void>;

Defined in: packages/api/src/window.ts:1136

Unminimizes the window.

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

Promise<void>

A promise indicating the success or failure of the operation.

Window.unminimize

static getAll(): Promise<WebviewWindow[]>;

Defined in: packages/api/src/webviewWindow.ts:132

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

Promise<WebviewWindow[]>

Webview.getAll

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

Defined in: packages/api/src/webviewWindow.ts:112

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

import { WebviewWindow } from '@tauri-apps/api/webviewWindow';
const mainWebview = WebviewWindow.getByLabel('main');
Parameter Type Description
label string The webview label.

Promise< | WebviewWindow | null>

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

Webview.getByLabel

static getCurrent(): WebviewWindow;

Defined in: packages/api/src/webviewWindow.ts:125

Get an instance of Webview for the current webview.

WebviewWindow

Webview.getCurrent

Re-exports Color


Re-exports DragDropEvent


© 2026 Tauri Contributors. CC-BY / MIT