webview
Provides APIs to create webviews, communicate with other webviews and manipulate the current webview.
Webview events
Events can be listened to using Webview.listen:
References
DragDropEvent
Re-exports DragDropEvent
DragDropPayload
Re-exports DragDropPayload
Classes
Webview
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
Extended by
Constructors
new Webview()
Creates a new Webview.
Parameters
Parameter | Type | Description |
---|---|---|
window | Window | the window to add this webview to. |
label | string | The unique webview label. Must be alphanumeric: a-zA-Z-/:_ . |
options | WebviewOptions | - |
Returns
The Webview instance to communicate with the webview.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/webview.ts#L159
Properties
Property | Type | Description |
---|---|---|
label | string | The webview label. It is a unique identifier for the webview, can be used to reference it later. |
listeners | Record <string , EventCallback <any >[]> | Local event listeners. |
window | Window | The window hosting this webview. |
Methods
close()
Closes the webview.
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/webview.ts#L396
emit()
Emits an event to all targets.
Parameters
Parameter | Type | Description |
---|---|---|
event | string | Event name. Must include only alphanumeric characters, - , / , : and _ . |
payload ? | unknown | Event payload. |
Returns
Promise
<void
>
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/webview.ts#L285
emitTo()
Emits an event to all targets matching the given target.
Parameters
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 ? | unknown | Event payload. |
Returns
Promise
<void
>
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/webview.ts#L313
listen()
Listen to an emitted event on this webview.
Type parameters
Type parameter |
---|
T |
Parameters
Parameter | Type | Description |
---|---|---|
event | EventName | Event name. Must include only alphanumeric characters, - , / , : and _ . |
handler | EventCallback <T > | Event handler. |
Returns
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.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/webview.ts#L225
onDragDropEvent()
Listen to a file drop event. The listener is triggered when the user hovers the selected files on the webview, drops the files or cancels the operation.
Parameters
Parameter | Type |
---|---|
handler | EventCallback <DragDropEvent > |
Returns
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.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/webview.ts#L544
once()
Listen to an emitted event on this webview only once.
Type parameters
Type parameter |
---|
T |
Parameters
Parameter | Type | Description |
---|---|---|
event | string | Event name. Must include only alphanumeric characters, - , / , : and _ . |
handler | EventCallback <T > | Event handler. |
Returns
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.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/webview.ts#L260
position()
The position of the top-left hand corner of the webview’s client area relative to the top-left hand corner of the desktop.
Returns
The webview’s position.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/webview.ts#L358
reparent()
Moves this webview to the given label.
Parameters
Parameter | Type |
---|---|
window | string | Window | WebviewWindow |
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/webview.ts#L510
setFocus()
Bring the webview to front and focus.
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/webview.ts#L477
setPosition()
Sets the webview position.
Parameters
Parameter | Type | Description |
---|---|---|
position | LogicalPosition | PhysicalPosition | The new position, in logical or physical pixels. |
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/webview.ts#L443
setSize()
Resizes the webview.
Parameters
Parameter | Type | Description |
---|---|---|
size | LogicalSize | PhysicalSize | The logical or physical size. |
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/webview.ts#L413
setZoom()
Set webview zoom level.
Parameters
Parameter | Type |
---|---|
scaleFactor | number |
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/webview.ts#L493
size()
The physical size of the webview’s client area. The client area is the content of the webview, excluding the title bar and borders.
Returns
The webview’s size.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/webview.ts#L375
getAll()
Gets a list of instances of Webview
for all available webviews.
Returns
Webview
[]
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/webview.ts#L202
getByLabel()
Gets the Webview for the webview associated with the given label.
Parameters
Parameter | Type | Description |
---|---|---|
label | string | The webview label. |
Returns
null
| Webview
The Webview instance to communicate with the webview or null if the webview doesn’t exist.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/webview.ts#L188
getCurrent()
Get an instance of Webview
for the current webview.
Returns
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/webview.ts#L195
Interfaces
WebviewOptions
Configuration for the webview to create.
Since
2.0.0
Properties
Property | Type | Description |
---|---|---|
acceptFirstMouse? | boolean | Whether clicking an inactive webview also clicks through to the webview on macOS. |
dragDropEnabled? | boolean | Whether the drag and drop is enabled or not on the webview. By default it is enabled. Disabling it is required to use HTML5 drag and drop on the frontend on Windows. |
height | number | The initial height. |
incognito? | boolean | Whether or not the webview should be launched in incognito mode. Platform-specific
|
proxyUrl? | string | The proxy URL for the WebView for all network requests. Must be either a Platform-specific
|
transparent? | boolean | Whether the webview is transparent or not. Note that on macOS this requires the macos-private-api feature flag, enabled under tauri.conf.json > app > macOSPrivateApi . WARNING: Using private APIs on macOS prevents your application from being accepted to the App Store . |
url? | string | Remote URL or local file path to open.
|
userAgent? | string | The user agent for the webview. |
width | number | The initial width. |
x | number | The initial vertical position. |
y | number | The initial horizontal position. |
zoomHotkeysEnabled? | boolean | Whether page zooming by hotkeys is enabled Platform-specific:
webview:allow-set-webview-zoom permission
|
Functions
getAll()
Gets a list of instances of Webview
for all available webviews.
Returns
Webview
[]
Since
2.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/webview.ts#L73
getCurrent()
Get an instance of Webview
for the current webview.
Returns
Since
2.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/webview.ts#L57
© 2024 Tauri Contributors. CC-BY / MIT