pub struct WebviewWindowBuilder<'a, R: Runtime, M: Manager<R>> { /* private fields */ }Expand description
A builder for WebviewWindow, a window that hosts a single webview.
Implementations§
Source§impl<'a, R: Runtime, M: Manager<R>> WebviewWindowBuilder<'a, R, M>
impl<'a, R: Runtime, M: Manager<R>> WebviewWindowBuilder<'a, R, M>
Sourcepub fn new<L: Into<String>>(manager: &'a M, label: L, url: WebviewUrl) -> Self
pub fn new<L: Into<String>>(manager: &'a M, label: L, url: WebviewUrl) -> Self
Initializes a webview window builder with the given window label.
§Known issues
On Windows, this function deadlocks when used in a synchronous command and event handlers, see the Webview2 issue.
You should use async commands and separate threads when creating windows.
§Examples
- Create a window in the setup hook:
tauri::Builder::default()
.setup(|app| {
let webview_window = tauri::WebviewWindowBuilder::new(app, "label", tauri::WebviewUrl::App("index.html".into()))
.build()?;
Ok(())
});- Create a window in a separate thread:
tauri::Builder::default()
.setup(|app| {
let handle = app.handle().clone();
std::thread::spawn(move || {
let webview_window = tauri::WebviewWindowBuilder::new(&handle, "label", tauri::WebviewUrl::App("index.html".into()))
.build()
.unwrap();
});
Ok(())
});- Create a window in a command:
#[tauri::command]
async fn create_window(app: tauri::AppHandle) {
let webview_window = tauri::WebviewWindowBuilder::new(&app, "label", tauri::WebviewUrl::App("index.html".into()))
.build()
.unwrap();
}Sourcepub fn from_config(manager: &'a M, config: &WindowConfig) -> Result<Self>
pub fn from_config(manager: &'a M, config: &WindowConfig) -> Result<Self>
Initializes a webview window builder from a WindowConfig from tauri.conf.json.
Keep in mind that you can’t create 2 windows with the same label so make sure
that the initial window was closed or change the label of the cloned WindowConfig.
§Known issues
On Windows, this function deadlocks when used in a synchronous command or event handlers, see the Webview2 issue.
You should use async commands and separate threads when creating windows.
§Examples
- Create a window in a command:
#[tauri::command]
async fn reopen_window(app: tauri::AppHandle) {
let webview_window = tauri::WebviewWindowBuilder::from_config(&app, &app.config().app.windows.get(0).unwrap())
.unwrap()
.build()
.unwrap();
}- Create a window in a command from a config with a specific label, and change its label so multiple instances can exist:
#[tauri::command]
async fn open_window_multiple(app: tauri::AppHandle) {
let mut conf = app.config().app.windows.iter().find(|c| c.label == "template-for-multiwindow").unwrap().clone();
// This should be a unique label for all windows. For example, we can use a random suffix:
let mut buf = [0u8; 1];
assert_eq!(getrandom::fill(&mut buf), Ok(()));
conf.label = format!("my-multiwindow-{}", buf[0]);
let webview_window = tauri::WebviewWindowBuilder::from_config(&app, &conf)
.unwrap()
.build()
.unwrap();
}Available on desktop only.
desktop only.Registers a global menu event listener.
Note that this handler is called for any menu event, whether it is coming from this window, another window or from the tray icon menu.
Also note that this handler will not be called if the window used to register it was closed.
§Examples
use tauri::menu::{Menu, Submenu, MenuItem};
tauri::Builder::default()
.setup(|app| {
let handle = app.handle();
let save_menu_item = MenuItem::new(handle, "Save", true, None::<&str>)?;
let menu = Menu::with_items(handle, &[
&Submenu::with_items(handle, "File", true, &[
&save_menu_item,
])?,
])?;
let webview_window = tauri::WebviewWindowBuilder::new(app, "editor", tauri::WebviewUrl::App("index.html".into()))
.menu(menu)
.on_menu_event(move |window, event| {
if event.id == save_menu_item.id() {
// save menu item
}
})
.build()
.unwrap();
Ok(())
});Sourcepub fn on_web_resource_request<F: Fn(Request<Vec<u8>>, &mut Response<Cow<'static, [u8]>>) + Send + Sync + 'static>(
self,
f: F,
) -> Self
pub fn on_web_resource_request<F: Fn(Request<Vec<u8>>, &mut Response<Cow<'static, [u8]>>) + Send + Sync + 'static>( self, f: F, ) -> Self
Defines a closure to be executed when the webview makes an HTTP request for a web resource, allowing you to modify the response.
Currently only implemented for the tauri URI protocol.
NOTE: Currently this is not executed when using external URLs such as a development server, but it might be implemented in the future. Always check the request URL.
§Examples
use tauri::{
utils::config::{Csp, CspDirectiveSources, WebviewUrl},
webview::WebviewWindowBuilder,
};
use http::header::HeaderValue;
use std::collections::HashMap;
tauri::Builder::default()
.setup(|app| {
let webview_window = WebviewWindowBuilder::new(app, "core", WebviewUrl::App("index.html".into()))
.on_web_resource_request(|request, response| {
if request.uri().scheme_str() == Some("tauri") {
// if we have a CSP header, Tauri is loading an HTML file
// for this example, let's dynamically change the CSP
if let Some(csp) = response.headers_mut().get_mut("Content-Security-Policy") {
// use the tauri helper to parse the CSP policy to a map
let mut csp_map: HashMap<String, CspDirectiveSources> = Csp::Policy(csp.to_str().unwrap().to_string()).into();
csp_map.entry("script-src".to_string()).or_insert_with(Default::default).push("'unsafe-inline'");
// use the tauri helper to get a CSP string from the map
let csp_string = Csp::from(csp_map).to_string();
*csp = HeaderValue::from_str(&csp_string).unwrap();
}
}
})
.build()?;
Ok(())
});Defines a closure to be executed when the webview navigates to a URL. Returning false cancels the navigation.
§Examples
use tauri::{
utils::config::{Csp, CspDirectiveSources, WebviewUrl},
webview::WebviewWindowBuilder,
};
use http::header::HeaderValue;
use std::collections::HashMap;
tauri::Builder::default()
.setup(|app| {
let webview_window = WebviewWindowBuilder::new(app, "core", WebviewUrl::App("index.html".into()))
.on_navigation(|url| {
// allow the production URL or localhost on dev
url.scheme() == "tauri" || (cfg!(dev) && url.host_str() == Some("localhost"))
})
.build()?;
Ok(())
});Sourcepub fn on_new_window<F: Fn(Url, NewWindowFeatures) -> NewWindowResponse<R> + Send + Sync + 'static>(
self,
f: F,
) -> Self
pub fn on_new_window<F: Fn(Url, NewWindowFeatures) -> NewWindowResponse<R> + Send + Sync + 'static>( self, f: F, ) -> Self
Set a new window request handler to decide if incoming url is allowed to be opened.
A new window is requested to be opened by the window.open API.
The closure take the URL to open and the window features object and returns NewWindowResponse to determine whether the window should open.
§Examples
use tauri::{
utils::config::WebviewUrl,
webview::WebviewWindowBuilder,
};
use http::header::HeaderValue;
use std::collections::HashMap;
tauri::Builder::default()
.setup(|app| {
let app_ = app.handle().clone();
let webview_window = WebviewWindowBuilder::new(app, "core", WebviewUrl::App("index.html".into()))
.on_new_window(move |url, features| {
let builder = tauri::WebviewWindowBuilder::new(
&app_,
// note: add an ID counter or random label generator to support multiple opened windows at the same time
"opened-window",
tauri::WebviewUrl::External("about:blank".parse().unwrap()),
)
.window_features(features)
.on_document_title_changed(|window, title| {
window.set_title(&title).unwrap();
})
.title(url.as_str());
let window = builder.build().unwrap();
tauri::webview::NewWindowResponse::Create { window }
})
.build()?;
Ok(())
});§Platform-specific
- Android / iOS: Not supported.
- Windows: The closure is executed on a separate thread to prevent a deadlock.
Sourcepub fn on_document_title_changed<F: Fn(WebviewWindow<R>, String) + Send + 'static>(
self,
f: F,
) -> Self
pub fn on_document_title_changed<F: Fn(WebviewWindow<R>, String) + Send + 'static>( self, f: F, ) -> Self
Defines a closure to be executed when the document title changes.
Note that it may run before or after the navigation event.
Sourcepub fn on_download<F: Fn(Webview<R>, DownloadEvent<'_>) -> bool + Send + Sync + 'static>(
self,
f: F,
) -> Self
pub fn on_download<F: Fn(Webview<R>, DownloadEvent<'_>) -> bool + Send + Sync + 'static>( self, f: F, ) -> Self
Set a download event handler to be notified when a download is requested or finished.
Returning false prevents the download from happening on a DownloadEvent::Requested event.
§Examples
use tauri::{
utils::config::{Csp, CspDirectiveSources, WebviewUrl},
webview::{DownloadEvent, WebviewWindowBuilder},
};
tauri::Builder::default()
.setup(|app| {
let handle = app.handle();
let webview_window = WebviewWindowBuilder::new(handle, "core", WebviewUrl::App("index.html".into()))
.on_download(|webview, event| {
match event {
DownloadEvent::Requested { url, destination } => {
println!("downloading {}", url);
*destination = "/home/tauri/target/path".into();
}
DownloadEvent::Finished { url, path, success } => {
println!("downloaded {} to {:?}, success: {}", url, path, success);
}
_ => (),
}
// let the download start
true
})
.build()?;
Ok(())
});Sourcepub fn on_page_load<F: Fn(WebviewWindow<R>, PageLoadPayload<'_>) + Send + Sync + 'static>(
self,
f: F,
) -> Self
pub fn on_page_load<F: Fn(WebviewWindow<R>, PageLoadPayload<'_>) + Send + Sync + 'static>( self, f: F, ) -> Self
Defines a closure to be executed when a page load event is triggered.
The event can be either tauri_runtime::webview::PageLoadEvent::Started if the page has started loading
or tauri_runtime::webview::PageLoadEvent::Finished when the page finishes loading.
§Examples
use tauri::{
utils::config::{Csp, CspDirectiveSources, WebviewUrl},
webview::{PageLoadEvent, WebviewWindowBuilder},
};
use http::header::HeaderValue;
use std::collections::HashMap;
tauri::Builder::default()
.setup(|app| {
let webview_window = WebviewWindowBuilder::new(app, "core", WebviewUrl::App("index.html".into()))
.on_page_load(|window, payload| {
match payload.event() {
PageLoadEvent::Started => {
println!("{} finished loading", payload.url());
}
PageLoadEvent::Finished => {
println!("{} finished loading", payload.url());
}
}
})
.build()?;
Ok(())
});Sourcepub fn build(self) -> Result<WebviewWindow<R>>
pub fn build(self) -> Result<WebviewWindow<R>>
Creates a new window.
Source§impl<'a, R: Runtime, M: Manager<R>> WebviewWindowBuilder<'a, R, M>
Desktop APIs.
impl<'a, R: Runtime, M: Manager<R>> WebviewWindowBuilder<'a, R, M>
Desktop APIs.
Available on desktop only.
desktop only.Sets the menu for the window.
Sourcepub fn position(self, x: f64, y: f64) -> Self
Available on desktop only.
pub fn position(self, x: f64, y: f64) -> Self
desktop only.The initial position of the window in logical pixels.
Sourcepub fn inner_size(self, width: f64, height: f64) -> Self
Available on desktop only.
pub fn inner_size(self, width: f64, height: f64) -> Self
desktop only.Window size in logical pixels.
Sourcepub fn min_inner_size(self, min_width: f64, min_height: f64) -> Self
Available on desktop only.
pub fn min_inner_size(self, min_width: f64, min_height: f64) -> Self
desktop only.Window min inner size in logical pixels.
Sourcepub fn max_inner_size(self, max_width: f64, max_height: f64) -> Self
Available on desktop only.
pub fn max_inner_size(self, max_width: f64, max_height: f64) -> Self
desktop only.Window max inner size in logical pixels.
Sourcepub fn inner_size_constraints(self, constraints: WindowSizeConstraints) -> Self
Available on desktop only.
pub fn inner_size_constraints(self, constraints: WindowSizeConstraints) -> Self
desktop only.Window inner size constraints.
Sourcepub fn prevent_overflow(self) -> Self
Available on desktop only.
pub fn prevent_overflow(self) -> Self
desktop only.Prevent the window from overflowing the working area (e.g. monitor size - taskbar size)
on creation, which means the window size will be limited to monitor size - taskbar size
NOTE: The overflow check is only performed on window creation, resizes can still overflow
§Platform-specific
- iOS / Android: Unsupported.
Sourcepub fn prevent_overflow_with_margin(self, margin: impl Into<Size>) -> Self
Available on desktop only.
pub fn prevent_overflow_with_margin(self, margin: impl Into<Size>) -> Self
desktop only.Prevent the window from overflowing the working area (e.g. monitor size - taskbar size)
on creation with a margin, which means the window size will be limited to monitor size - taskbar size - margin size
NOTE: The overflow check is only performed on window creation, resizes can still overflow
§Platform-specific
- iOS / Android: Unsupported.
Sourcepub fn resizable(self, resizable: bool) -> Self
Available on desktop only.
pub fn resizable(self, resizable: bool) -> Self
desktop only.Whether the window is resizable or not. When resizable is set to false, native window’s maximize button is automatically disabled.
Sourcepub fn maximizable(self, maximizable: bool) -> Self
Available on desktop only.
pub fn maximizable(self, maximizable: bool) -> Self
desktop only.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.
Sourcepub fn minimizable(self, minimizable: bool) -> Self
Available on desktop only.
pub fn minimizable(self, minimizable: bool) -> Self
desktop only.Whether the window’s native minimize button is enabled or not.
§Platform-specific
- Linux / iOS / Android: Unsupported.
Sourcepub fn closable(self, closable: bool) -> Self
Available on desktop only.
pub fn closable(self, closable: bool) -> Self
desktop only.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.
Sourcepub fn title<S: Into<String>>(self, title: S) -> Self
Available on desktop only.
pub fn title<S: Into<String>>(self, title: S) -> Self
desktop only.The title of the window in the title bar.
Sourcepub fn fullscreen(self, fullscreen: bool) -> Self
Available on desktop only.
pub fn fullscreen(self, fullscreen: bool) -> Self
desktop only.Whether to start the window in fullscreen or not.
Sourcepub fn focus(self) -> Self
👎Deprecated since 1.2.0: The window is automatically focused by default. This function Will be removed in 3.0.0. Use focused instead.Available on desktop only.
pub fn focus(self) -> Self
focused instead.desktop only.Sets the window to be initially focused.
Sourcepub fn focusable(self, focusable: bool) -> Self
Available on desktop only.
pub fn focusable(self, focusable: bool) -> Self
desktop only.Whether the window will be focusable or not.
Sourcepub fn focused(self, focused: bool) -> Self
Available on desktop only.
pub fn focused(self, focused: bool) -> Self
desktop only.Whether the window will be initially focused or not.
Sourcepub fn maximized(self, maximized: bool) -> Self
Available on desktop only.
pub fn maximized(self, maximized: bool) -> Self
desktop only.Whether the window should be maximized upon creation.
Sourcepub fn visible(self, visible: bool) -> Self
Available on desktop only.
pub fn visible(self, visible: bool) -> Self
desktop only.Whether the window should be immediately visible upon creation.
Sourcepub fn theme(self, theme: Option<Theme>) -> Self
Available on desktop only.
pub fn theme(self, theme: Option<Theme>) -> Self
desktop only.Forces a theme or uses the system settings if None was provided.
§Platform-specific
- macOS: Only supported on macOS 10.14+.
Sourcepub fn decorations(self, decorations: bool) -> Self
Available on desktop only.
pub fn decorations(self, decorations: bool) -> Self
desktop only.Whether the window should have borders and bars.
Sourcepub fn always_on_bottom(self, always_on_bottom: bool) -> Self
Available on desktop only.
pub fn always_on_bottom(self, always_on_bottom: bool) -> Self
desktop only.Whether the window should always be below other windows.
Sourcepub fn always_on_top(self, always_on_top: bool) -> Self
Available on desktop only.
pub fn always_on_top(self, always_on_top: bool) -> Self
desktop only.Whether the window should always be on top of other windows.
Sourcepub fn visible_on_all_workspaces(self, visible_on_all_workspaces: bool) -> Self
Available on desktop only.
pub fn visible_on_all_workspaces(self, visible_on_all_workspaces: bool) -> Self
desktop only.Whether the window will be visible on all workspaces or virtual desktops.
Sourcepub fn content_protected(self, protected: bool) -> Self
Available on desktop only.
pub fn content_protected(self, protected: bool) -> Self
desktop only.Prevents the window contents from being captured by other apps.
Sourcepub fn icon(self, icon: Image<'a>) -> Result<Self>
Available on desktop only.
pub fn icon(self, icon: Image<'a>) -> Result<Self>
desktop only.Sets the window icon.
Sourcepub fn skip_taskbar(self, skip: bool) -> Self
Available on desktop only.
pub fn skip_taskbar(self, skip: bool) -> Self
desktop only.Sets whether or not the window icon should be hidden from the taskbar.
§Platform-specific
- macOS: Unsupported.
Sourcepub fn window_classname<S: Into<String>>(self, classname: S) -> Self
Available on desktop only.
pub fn window_classname<S: Into<String>>(self, classname: S) -> Self
desktop only.Sets custom name for Windows’ window class. Windows only.
Sourcepub fn shadow(self, enable: bool) -> Self
Available on desktop only.
pub fn shadow(self, enable: bool) -> Self
desktop only.Sets whether or not the window has shadow.
§Platform-specific
- Windows:
falsehas no effect on decorated window, shadows are always ON.truewill make undecorated window have a 1px white border, and on Windows 11, it will have a rounded corners.
- Linux: Unsupported.
Sourcepub fn parent(self, parent: &WebviewWindow<R>) -> Result<Self>
Available on desktop only.
pub fn parent(self, parent: &WebviewWindow<R>) -> Result<Self>
desktop only.Sets a parent to the window to be created.
§Platform-specific
- Windows: This sets the passed parent as an owner window to the window to be created.
From MSDN owned windows docs:
- An owned window is always above its owner in the z-order.
- The system automatically destroys an owned window when its owner is destroyed.
- An owned window is hidden when its owner is minimized.
- Linux: This makes the new window transient for parent, see https://docs.gtk.org/gtk3/method.Window.set_transient_for.html
- macOS: This adds the window as a child of parent, see https://developer.apple.com/documentation/appkit/nswindow/1419152-addchildwindow?language=objc
Sourcepub fn transient_for(self, parent: &WebviewWindow<R>) -> Result<Self>
Available on desktop and (Linux or DragonFly BSD or FreeBSD or NetBSD or OpenBSD) only.
pub fn transient_for(self, parent: &WebviewWindow<R>) -> Result<Self>
desktop and (Linux or DragonFly BSD or FreeBSD or NetBSD or OpenBSD) only.Sets the window to be created transient for parent.
See https://docs.gtk.org/gtk3/method.Window.set_transient_for.html
Sourcepub fn transient_for_raw(self, parent: &impl IsA<Window>) -> Self
Available on desktop and (Linux or DragonFly BSD or FreeBSD or NetBSD or OpenBSD) only.
pub fn transient_for_raw(self, parent: &impl IsA<Window>) -> Self
desktop and (Linux or DragonFly BSD or FreeBSD or NetBSD or OpenBSD) only.Sets the window to be created transient for parent.
See https://docs.gtk.org/gtk3/method.Window.set_transient_for.html
Sourcepub fn effects(self, effects: WindowEffectsConfig) -> Self
Available on desktop only.
pub fn effects(self, effects: WindowEffectsConfig) -> Self
desktop only.Sets window effects.
Requires the window to be transparent.
§Platform-specific:
- Windows: If using decorations or shadows, you may want to try this workaround https://github.com/tauri-apps/tao/issues/72#issuecomment-975607891
- Linux: Unsupported
Source§impl<R: Runtime, M: Manager<R>> WebviewWindowBuilder<'_, R, M>
Webview attributes.
impl<R: Runtime, M: Manager<R>> WebviewWindowBuilder<'_, R, M>
Webview attributes.
Sourcepub fn accept_first_mouse(self, accept: bool) -> Self
pub fn accept_first_mouse(self, accept: bool) -> Self
Sets whether clicking an inactive window also clicks through to the webview.
Sourcepub fn initialization_script(self, script: impl Into<String>) -> Self
pub fn initialization_script(self, script: impl Into<String>) -> Self
Adds the provided JavaScript to a list of scripts that should be run after the global object has been created, but before the HTML document has been parsed and before any other script included by the HTML document is run.
Since it runs on all top-level document navigations,
it’s recommended to check the window.location to guard your script from running on unexpected origins.
This is executed only on the main frame. If you only want to run it in all frames, use Self::initialization_script_for_all_frames instead.
§Platform-specific
- Windows: scripts are always added to subframes.
- Android: When [addDocumentStartJavaScript] is not supported, we prepend initialization scripts to each HTML head (implementation only supported on custom protocol URLs). For remote URLs, we use [onPageStarted] which is not guaranteed to run before other scripts.
§Examples
const INIT_SCRIPT: &str = r#"
if (window.location.origin === 'https://tauri.app') {
console.log("hello world from js init script");
window.__MY_CUSTOM_PROPERTY__ = { foo: 'bar' };
}
"#;
fn main() {
tauri::Builder::default()
.setup(|app| {
let webview = tauri::WebviewWindowBuilder::new(app, "label", tauri::WebviewUrl::App("index.html".into()))
.initialization_script(INIT_SCRIPT)
.build()?;
Ok(())
});
}Sourcepub fn initialization_script_for_all_frames(
self,
script: impl Into<String>,
) -> Self
pub fn initialization_script_for_all_frames( self, script: impl Into<String>, ) -> Self
Adds the provided JavaScript to a list of scripts that should be run after the global object has been created, but before the HTML document has been parsed and before any other script included by the HTML document is run.
Since it runs on all top-level document navigations and also child frame page navigations,
it’s recommended to check the window.location to guard your script from running on unexpected origins.
This is executed on all frames (main frame and also sub frames). If you only want to run the script in the main frame, use Self::initialization_script instead.
§Platform-specific
- Android: When [addDocumentStartJavaScript] is not supported, we prepend initialization scripts to each HTML head (implementation only supported on custom protocol URLs). For remote URLs, we use [onPageStarted] which is not guaranteed to run before other scripts.
§Examples
const INIT_SCRIPT: &str = r#"
if (window.location.origin === 'https://tauri.app') {
console.log("hello world from js init script");
window.__MY_CUSTOM_PROPERTY__ = { foo: 'bar' };
}
"#;
fn main() {
tauri::Builder::default()
.setup(|app| {
let webview = tauri::WebviewWindowBuilder::new(app, "label", tauri::WebviewUrl::App("index.html".into()))
.initialization_script_for_all_frames(INIT_SCRIPT)
.build()?;
Ok(())
});
}Sourcepub fn user_agent(self, user_agent: &str) -> Self
pub fn user_agent(self, user_agent: &str) -> Self
Set the user agent for the webview
Sourcepub fn additional_browser_args(self, additional_args: &str) -> Self
pub fn additional_browser_args(self, additional_args: &str) -> Self
Sourcepub fn data_directory(self, data_directory: PathBuf) -> Self
pub fn data_directory(self, data_directory: PathBuf) -> Self
Data directory for the webview.
Sourcepub fn disable_drag_drop_handler(self) -> Self
pub fn disable_drag_drop_handler(self) -> Self
Disables the drag and drop handler. This is required to use HTML5 drag and drop APIs on the frontend on Windows.
Sourcepub fn enable_clipboard_access(self) -> Self
pub fn enable_clipboard_access(self) -> Self
Enables clipboard access for the page rendered on Linux and Windows.
macOS doesn’t provide such method and is always enabled by default, but you still need to add menu item accelerators to use shortcuts.
Sourcepub fn auto_resize(self) -> Self
pub fn auto_resize(self) -> Self
Sets the webview to automatically grow and shrink its size and position when the parent window resizes.
Sourcepub fn proxy_url(self, url: Url) -> Self
pub fn proxy_url(self, url: Url) -> Self
Set a proxy URL for the WebView for all network requests.
Must be either a http:// or a socks5:// URL.
Sourcepub fn transparent(self, transparent: bool) -> Self
Available on non-macOS or crate feature macos-private-api only.
pub fn transparent(self, transparent: bool) -> Self
macos-private-api only.Whether the window should be transparent. If this is true, writing colors
with alpha values different than 1.0 will produce a transparent window.
Sourcepub fn zoom_hotkeys_enabled(self, enabled: bool) -> Self
pub fn zoom_hotkeys_enabled(self, enabled: bool) -> Self
Whether page zooming by hotkeys and mousewheel should be enabled or not.
§Platform-specific:
-
Windows: Controls WebView2’s
IsZoomControlEnabledsetting. -
MacOS / Linux: Injects a polyfill that zooms in and out with
Ctrl/Cmd + [- = +]hotkeys or mousewheel events, 20% in each step, ranging from 20% to 1000%. Requirescore:webview:allow-set-webview-zoompermission -
Android / iOS: Unsupported.
Sourcepub fn browser_extensions_enabled(self, enabled: bool) -> Self
pub fn browser_extensions_enabled(self, enabled: bool) -> Self
Whether browser extensions can be installed for the webview process
§Platform-specific:
- Windows: Enables the WebView2 environment’s
AreBrowserExtensionsEnabled - MacOS / Linux / iOS / Android - Unsupported.
Sourcepub fn extensions_path(self, path: impl AsRef<Path>) -> Self
pub fn extensions_path(self, path: impl AsRef<Path>) -> Self
Set the path from which to load extensions from. Extensions stored in this path should be unpacked Chrome extensions on Windows, and compiled .so extensions on Linux.
§Platform-specific:
- Windows: Browser extensions must first be enabled. See
browser_extensions_enabled - MacOS / iOS / Android - Unsupported.
Sourcepub fn data_store_identifier(self, data_store_identifier: [u8; 16]) -> Self
pub fn data_store_identifier(self, data_store_identifier: [u8; 16]) -> Self
Initialize the WebView with a custom data store identifier. Can be used as a replacement for data_directory not being available in WKWebView.
- macOS / iOS: Available on macOS >= 14 and iOS >= 17
- Windows / Linux / Android: Unsupported.
Sourcepub fn use_https_scheme(self, enabled: bool) -> Self
pub fn use_https_scheme(self, enabled: bool) -> Self
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 the old data.
Sourcepub fn devtools(self, enabled: bool) -> Self
pub fn devtools(self, enabled: bool) -> Self
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/#devicesin Chrome to get the devtools window. Wry’sWebViewdevtools API isn’t supported on Android. - iOS: Open Safari > Develop > [Your Device Name] > [Your WebView] to get the devtools window.
Sourcepub fn background_color(self, color: Color) -> Self
pub fn background_color(self, color: Color) -> Self
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.
Sourcepub fn background_throttling(self, policy: BackgroundThrottlingPolicy) -> Self
pub fn background_throttling(self, policy: BackgroundThrottlingPolicy) -> Self
Change the default background throttling behaviour.
By default, browsers use a suspend policy that will throttle timers and even unload the whole tab (view) to free resources after roughly 5 minutes when a view became minimized or hidden. This will pause all tasks until the documents visibility state changes back from hidden to visible by bringing the view back to the foreground.
§Platform-specific
- Linux / Windows / Android: Unsupported. Workarounds like a pending WebLock transaction might suffice.
- iOS: Supported since version 17.0+.
- macOS: Supported since version 14.0+.
see https://github.com/tauri-apps/tauri/issues/5250#issuecomment-2569380578
Sourcepub fn disable_javascript(self) -> Self
pub fn disable_javascript(self) -> Self
Whether JavaScript should be disabled.
Sourcepub fn scroll_bar_style(self, style: ScrollBarStyle) -> Self
pub fn scroll_bar_style(self, style: ScrollBarStyle) -> Self
Specifies the native scrollbar style to use with the webview. CSS styles that modifier the scrollbar are applied on top of the native appearance configured here.
Defaults to ScrollBarStyle::Default, which is the browser default.
§Platform-specific
- Windows:
- [
ScrollBarStyle::FluentOverlay] requires WebView2 Runtime version 125.0.2535.41 or higher, and does nothing on older versions. - This option must be given the same value for all webviews that target the same data directory. Use
WebviewWindowBuilder::data_directoryto change data directories if needed.
- [
- Linux / Android / iOS / macOS: Unsupported. Only supports
Defaultand performs no operation.
Available on crate feature wry and (Linux or DragonFly BSD or FreeBSD or NetBSD or OpenBSD) only.
wry and (Linux or DragonFly BSD or FreeBSD or NetBSD or OpenBSD) only.Creates a new webview sharing the same web process with the provided webview.
Useful if you need to link a webview to another, for instance when using the Self::on_new_window.
Sourcepub fn window_features(self, features: NewWindowFeatures) -> Self
Available on macOS or Windows or Linux or DragonFly BSD or FreeBSD or NetBSD or OpenBSD only.
pub fn window_features(self, features: NewWindowFeatures) -> Self
Set the window features.
Useful if you need to share the same window features, for instance when using the Self::on_new_window.