webview
Ce contenu n’est pas encore disponible dans votre langue.
Provides APIs to create webviews, communicate with other webviews and manipulate the current webview.
Webview events
Events can be listened to using Webview.listen:
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/packages/api/src/webview.ts#L160
Properties
Property | Type | Description | Defined in |
---|---|---|---|
label | string | The webview label. It is a unique identifier for the webview, can be used to reference it later. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/webview.ts#L131 |
listeners | Record <string , EventCallback <any >[]> | Local event listeners. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/webview.ts#L136 |
window | Window | The window hosting this webview. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/webview.ts#L133 |
Methods
clearAllBrowsingData()
Clears all browsing data for this webview.
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/webview.ts#L536
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/packages/api/src/webview.ts#L400
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/packages/api/src/webview.ts#L289
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/packages/api/src/webview.ts#L317
hide()
Hide 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/packages/api/src/webview.ts#L470
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/packages/api/src/webview.ts#L226
once()
Listen to an emitted event on this webview only once.
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/packages/api/src/webview.ts#L261
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/packages/api/src/webview.ts#L585
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/packages/api/src/webview.ts#L362
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/packages/api/src/webview.ts#L519
setBackgroundColor()
Specify the webview background color.
Platfrom-specific:
- macOS / iOS: Not implemented.
- Windows:
- On Windows 7, transparency is not supported and the alpha value will be ignored.
- On Windows higher than 7: translucent colors are not supported so any alpha value other than
0
will be replaced by255
Parameters
Parameter | Type |
---|---|
color | null | Color |
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Since
2.1.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/webview.ts#L554
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/packages/api/src/webview.ts#L454
setPosition()
Sets the webview position.
Parameters
Parameter | Type | Description |
---|---|---|
position | LogicalPosition | PhysicalPosition | Position | 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/packages/api/src/webview.ts#L435
setSize()
Resizes the webview.
Parameters
Parameter | Type | Description |
---|---|---|
size | LogicalSize | PhysicalSize | Size | 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/packages/api/src/webview.ts#L417
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/packages/api/src/webview.ts#L502
show()
Show 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/packages/api/src/webview.ts#L486
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/packages/api/src/webview.ts#L379
getAll()
Gets a list of instances of Webview
for all available webviews.
Returns
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/webview.ts#L203
getByLabel()
Gets the Webview for the webview associated with the given label.
Parameters
Parameter | Type | Description |
---|---|---|
label | string | The webview label. |
Returns
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/packages/api/src/webview.ts#L189
getCurrent()
Get an instance of Webview
for the current webview.
Returns
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/webview.ts#L196
Interfaces
WebviewOptions
Configuration for the webview to create.
Since
2.0.0
Properties
Property | Type | Description | Defined in |
---|---|---|---|
acceptFirstMouse? | boolean | Whether clicking an inactive webview also clicks through to the webview on macOS. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/webview.ts#L690 |
backgroundColor? | Color | Set the window and webview background color. #### Platform-specific: - macOS / iOS: Not implemented. - Windows: - On Windows 7, alpha channel is ignored. - On Windows 8 and newer, if alpha channel is not 0 , it will be ignored. Since 2.1.0 | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/webview.ts#L766 |
devtools? | boolean | Whether web inspector, which is usually called browser devtools, is enabled or not. Enabled by default. This API works in debug builds, but requires devtools feature flag to enable it in release builds. #### Platform-specific - macOS: This will call private functions on macOS. - Android: Open chrome://inspect/#devices in Chrome to get the devtools window. Wry’s WebView devtools API isn’t supported on Android. - iOS: Open Safari > Develop > [Your Device Name] > [Your WebView] to get the devtools window. Since 2.1.0 | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/webview.ts#L753 |
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. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/webview.ts#L686 |
focus? | boolean | Whether the webview should have focus or not Since 2.1.0 | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/webview.ts#L680 |
height | number | The initial height. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/webview.ts#L668 |
incognito? | boolean | Whether or not the webview should be launched in incognito mode. #### Platform-specific - Android: Unsupported. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/webview.ts#L702 |
proxyUrl? | string | The proxy URL for the WebView for all network requests. Must be either a http:// or a socks5:// URL. #### Platform-specific - macOS: Requires the macos-proxy feature flag and only compiles for macOS 14+. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/webview.ts#L712 |
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 . | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/webview.ts#L674 |
url? | string | Remote URL or local file path to open. - URL such as https://github.com/tauri-apps is opened directly on a Tauri webview. - data: URL such as data:text/html,<html>... is only supported with the webview-data-url Cargo feature for the tauri dependency. - local file path or route such as /path/to/page.html or /users is appended to the application URL (the devServer URL on development, or tauri://localhost/ and https://tauri.localhost/ on production). | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/webview.ts#L660 |
useHttpsScheme? | boolean | Sets whether the custom protocols should use https://<scheme>.localhost instead of the default http://<scheme>.localhost on Windows and Android. Defaults to false . #### Note Using a https scheme will NOT allow mixed content when trying to fetch http endpoints and therefore will not match the behavior of the <scheme>://localhost protocols used on macOS and Linux. #### Warning Changing this value between releases will change the IndexedDB, cookies and localstorage location and your app will not be able to access them. Since 2.1.0 | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/webview.ts#L739 |
userAgent? | string | The user agent for the webview. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/webview.ts#L694 |
width | number | The initial width. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/webview.ts#L666 |
x | number | The initial vertical position. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/webview.ts#L662 |
y | number | The initial horizontal position. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/webview.ts#L664 |
zoomHotkeysEnabled? | boolean | Whether page zooming by hotkeys is enabled #### Platform-specific: - Windows: Controls WebView2’s IsZoomControlEnabled setting. - MacOS / Linux: Injects a polyfill that zooms in and out with ctrl/command + -/= , 20% in each step, ranging from 20% to 1000%. Requires webview:allow-set-webview-zoom permission - Android / iOS: Unsupported. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/webview.ts#L724 |
Type Aliases
Color
An RGBA color. Each value has minimum of 0 and maximum of 255.
It can be either a string #ffffff
, an array of 3 or 4 elements or an object.
Since
2.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1945
DragDropEvent
The drag and drop event types.
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/webview.ts#L37
Functions
getAllWebviews()
Gets a list of instances of Webview
for all available webviews.
Returns
Since
2.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/webview.ts#L64
getCurrentWebview()
Get an instance of Webview
for the current webview.
Returns
Since
2.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/webview.ts#L48
© 2024 Tauri Contributors. CC-BY / MIT