The unique webview label. Must be alphanumeric: a-zA-Z-/:_
.
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
});
The window hosting this webview.
The webview label. It is a unique identifier for the webview, can be used to reference it later.
Local event listeners.
Emits an event to all targets matching the given target.
Label of the target Window/Webview/WebviewWindow or raw EventTarget object.
Event name. Must include only alphanumeric characters, -
, /
, :
and _
.
Optional
payload: TEvent payload.
The position of the top-left hand corner of the webview's client area relative to the top-left hand corner of the desktop.
The webview's position.
The physical size of the webview's client area. The client area is the content of the webview, excluding the title bar and borders.
The webview's size.
Closes the webview.
A promise indicating the success or failure of the operation.
Resizes the webview.
The logical or physical size.
A promise indicating the success or failure of the operation.
Sets the webview position.
The new position, in logical or physical pixels.
A promise indicating the success or failure of the operation.
Bring the webview to front and focus.
A promise indicating the success or failure of the operation.
Sets whether the webview should automatically grow and shrink its size and position when the parent window resizes.
A promise indicating the success or failure of the operation.
Hide the webview.
A promise indicating the success or failure of the operation.
Show the webview.
A promise indicating the success or failure of the operation.
Set webview zoom level.
A promise indicating the success or failure of the operation.
Moves this webview to the given label.
A promise indicating the success or failure of the operation.
Clears all browsing data for this webview.
A promise indicating the success or failure of the operation.
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.
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.
Static
getGets the Webview for the webview associated with the given label.
The webview label.
The Webview instance to communicate with the webview or null if the webview doesn't exist.
Static
getGet an instance of Webview
for the current webview.
Static
getGets a list of instances of Webview
for all available webviews.
Listen to an emitted event on this webivew window.
Event name. Must include only alphanumeric characters, -
, /
, :
and _
.
Event handler.
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();
Listen to an emitted event on this webview window only once.
Event name. Must include only alphanumeric characters, -
, /
, :
and _
.
Event handler.
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();
Set the window and webview background color.
0
, it will be ignored.A promise indicating the success or failure of the operation.
The scale factor that can be used to map physical pixels to logical pixels.
The window's monitor scale factor.
The position of the top-left hand corner of the window's client area relative to the top-left hand corner of the desktop.
The window's inner position.
The position of the top-left hand corner of the window relative to the top-left hand corner of the desktop.
The window's outer position.
The physical size of the window's client area. The client area is the content of the window, excluding the title bar and borders.
The window's inner size.
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.
The window's outer size.
Gets the window's current fullscreen state.
Whether the window is in fullscreen mode or not.
Gets the window's current minimized state.
Gets the window's current maximized state.
Whether the window is maximized or not.
Gets the window's current focus state.
Whether the window is focused or not.
Gets the window's current decorated state.
Whether the window is decorated or not.
Gets the window's current resizable state.
Whether the window is resizable or not.
Gets the window's native maximize button state.
Whether the window's native maximize button is enabled or not.
Gets the window's native minimize button state.
Whether the window's native minimize button is enabled or not.
Whether the window's native close button is enabled or not.
Gets the window's current visible state.
Whether the window is visible or not.
Gets the window's current title.
Whether the window is configured to be always on top of other windows or not.
Whether the window is visible or not.
Centers the window.
A promise indicating the success or failure of the operation.
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.
null
has no effect.A promise indicating the success or failure of the operation.
Updates the window resizable flag.
A promise indicating the success or failure of the operation.
Enable or disable the window.
A promise indicating the success or failure of the operation.
Whether the window is enabled or disabled.
A promise indicating the success or failure of the operation.
Sets whether the window's native maximize button is enabled or not. If resizable is set to false, this setting is ignored.
A promise indicating the success or failure of the operation.
Sets whether the window's native minimize button is enabled or not.
A promise indicating the success or failure of the operation.
Sets whether the window's native close button is enabled or not.
A promise indicating the success or failure of the operation.
Sets the window title.
The new title
A promise indicating the success or failure of the operation.
Maximizes the window.
A promise indicating the success or failure of the operation.
Unmaximizes the window.
A promise indicating the success or failure of the operation.
Toggles the window maximized state.
A promise indicating the success or failure of the operation.
Minimizes the window.
A promise indicating the success or failure of the operation.
Unminimizes the window.
A promise indicating the success or failure of the operation.
Destroys the window. Behaves like Window.close but forces the window close instead of emitting a closeRequested event.
A promise indicating the success or failure of the operation.
Whether the window should have borders and bars.
Whether the window should have borders and bars.
A promise indicating the success or failure of the operation.
Whether or not the window should have shadow.
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.A promise indicating the success or failure of the operation.
Clear any applied effects if possible.
Whether the window should always be on top of other windows.
Whether the window should always be on top of other windows or not.
A promise indicating the success or failure of the operation.
Whether the window should always be below other windows.
Whether the window should always be below other windows or not.
A promise indicating the success or failure of the operation.
Prevents the window contents from being captured by other apps.
A promise indicating the success or failure of the operation.
Sets the window minimum inner size. If the size
argument is not provided, the constraint is unset.
The logical or physical inner size, or null
to unset the constraint.
A promise indicating the success or failure of the operation.
Sets the window maximum inner size. If the size
argument is undefined, the constraint is unset.
The logical or physical inner size, or null
to unset the constraint.
A promise indicating the success or failure of the operation.
Sets the window inner size constraints.
The logical or physical inner size, or null
to unset the constraint.
A promise indicating the success or failure of the operation.
Sets the window fullscreen state.
Whether the window should go to fullscreen or not.
A promise indicating the success or failure of the operation.
Sets the window icon.
Icon bytes or path to the icon file.
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"] }
Whether the window icon should be hidden from the taskbar or not.
true to hide window icon, false to show it.
A promise indicating the success or failure of the operation.
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.
true
to grab the cursor icon, false
to release it.
A promise indicating the success or failure of the operation.
Modifies the cursor's visibility.
If false
, this will hide the cursor. If true
, this will show the cursor.
A promise indicating the success or failure of the operation.
Modifies the cursor icon of the window.
The new cursor icon.
A promise indicating the success or failure of the operation.
Changes the position of the cursor in window coordinates.
The new cursor position.
A promise indicating the success or failure of the operation.
Changes the cursor events behavior.
true
to ignore the cursor events; false
to process them as usual.
A promise indicating the success or failure of the operation.
Starts dragging the window.
A promise indicating the success or failure of the operation.
Starts resize-dragging the window.
A promise indicating the success or failure of the operation.
Sets the badge count. It is app wide and not specific to this window.
Optional
count: numberThe badge count. Use undefined
to remove the badge.
A promise indicating the success or failure of the operation.
Sets the badge cont macOS only.
Optional
label: stringThe badge label. Use undefined
to remove the badge.
A promise indicating the success or failure of the operation.
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"] }
Optional
icon: string | number[] | ArrayBuffer | Uint8Array<ArrayBufferLike> | ImageIcon bytes or path to the icon file. Use undefined
to remove the overlay icon.
A promise indicating the success or failure of the operation.
Sets the taskbar progress state.
libunity
(e.g. GNOME).A promise indicating the success or failure of the operation.
Sets whether the window should be visible on all workspaces or virtual desktops.
Listen to window resize.
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.
Listen to window move.
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.
Listen to window close requested. Emitted when the user requests to closes the window.
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();
Listen to window focus change.
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();
Listen to window scale change. Emitted when the window's scale factor has changed. The following user actions can cause DPI changes:
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();
Listen to the system theme change.
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.
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
Since
2.0.0