pub struct WebviewWindow<R: Runtime = Wry> { /* private fields */ }Implementations§
Source§impl<R: Runtime> WebviewWindow<R>
Base webview window functions.
impl<R: Runtime> WebviewWindow<R>
Base webview window functions.
Sourcepub fn builder<M: Manager<R>, L: Into<String>>(
manager: &M,
label: L,
url: WebviewUrl,
) -> WebviewWindowBuilder<'_, R, M>
pub fn builder<M: Manager<R>, L: Into<String>>( manager: &M, label: L, url: WebviewUrl, ) -> WebviewWindowBuilder<'_, R, M>
Initializes a WebviewWindowBuilder with the given window label and webview URL.
Data URLs are only supported with the webview-data-url feature flag.
Sourcepub fn run_on_main_thread<F: FnOnce() + Send + 'static>(
&self,
f: F,
) -> Result<()>
pub fn run_on_main_thread<F: FnOnce() + Send + 'static>( &self, f: F, ) -> Result<()>
Runs the given closure on the main thread.
Sourcepub fn on_window_event<F: Fn(&WindowEvent) + Send + 'static>(&self, f: F)
pub fn on_window_event<F: Fn(&WindowEvent) + Send + 'static>(&self, f: F)
Registers a window event listener.
Sourcepub fn resolve_command_scope<T: ScopeObject>(
&self,
plugin: &str,
command: &str,
) -> Result<Option<ResolvedScope<T>>>
pub fn resolve_command_scope<T: ScopeObject>( &self, plugin: &str, command: &str, ) -> Result<Option<ResolvedScope<T>>>
Resolves the given command scope for this webview on the currently loaded URL.
If the command is not allowed, returns None.
If the scope cannot be deserialized to the given type, an error is returned.
In a command context this can be directly resolved from the command arguments via crate::ipc::CommandScope:
use tauri::ipc::CommandScope;
#[derive(Debug, serde::Deserialize)]
struct ScopeType {
some_value: String,
}
#[tauri::command]
fn my_command(scope: CommandScope<ScopeType>) {
// check scope
}§Examples
use tauri::Manager;
#[derive(Debug, serde::Deserialize)]
struct ScopeType {
some_value: String,
}
tauri::Builder::default()
.setup(|app| {
let webview = app.get_webview_window("main").unwrap();
let scope = webview.resolve_command_scope::<ScopeType>("my-plugin", "read");
Ok(())
});Source§impl<R: Runtime> WebviewWindow<R>
Window getters.
impl<R: Runtime> WebviewWindow<R>
Window getters.
Sourcepub fn scale_factor(&self) -> Result<f64>
pub fn scale_factor(&self) -> Result<f64>
Returns the scale factor that can be used to map logical pixels to physical pixels, and vice versa.
Sourcepub fn inner_position(&self) -> Result<PhysicalPosition<i32>>
pub fn inner_position(&self) -> Result<PhysicalPosition<i32>>
Returns the position of the top-left hand corner of the window’s client area relative to the top-left hand corner of the desktop.
Sourcepub fn outer_position(&self) -> Result<PhysicalPosition<i32>>
pub fn outer_position(&self) -> Result<PhysicalPosition<i32>>
Returns the position of the top-left hand corner of the window relative to the top-left hand corner of the desktop.
Sourcepub fn inner_size(&self) -> Result<PhysicalSize<u32>>
pub fn inner_size(&self) -> Result<PhysicalSize<u32>>
Returns the physical size of the window’s client area.
The client area is the content of the window, excluding the title bar and borders.
Sourcepub fn outer_size(&self) -> Result<PhysicalSize<u32>>
pub fn outer_size(&self) -> Result<PhysicalSize<u32>>
Returns 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.
Sourcepub fn is_fullscreen(&self) -> Result<bool>
pub fn is_fullscreen(&self) -> Result<bool>
Gets the window’s current fullscreen state.
Sourcepub fn is_minimized(&self) -> Result<bool>
pub fn is_minimized(&self) -> Result<bool>
Gets the window’s current minimized state.
Sourcepub fn is_maximized(&self) -> Result<bool>
pub fn is_maximized(&self) -> Result<bool>
Gets the window’s current maximized state.
Sourcepub fn is_focused(&self) -> Result<bool>
pub fn is_focused(&self) -> Result<bool>
Gets the window’s current focus state.
Sourcepub fn is_decorated(&self) -> Result<bool>
pub fn is_decorated(&self) -> Result<bool>
Gets the window’s current decoration state.
Sourcepub fn is_resizable(&self) -> Result<bool>
pub fn is_resizable(&self) -> Result<bool>
Gets the window’s current resizable state.
Sourcepub fn is_enabled(&self) -> Result<bool>
pub fn is_enabled(&self) -> Result<bool>
Whether the window is enabled or disabled.
Sourcepub fn is_always_on_top(&self) -> Result<bool>
pub fn is_always_on_top(&self) -> Result<bool>
Determines if this window should always be on top of other windows.
§Platform-specific
- iOS / Android: Unsupported.
Sourcepub fn is_maximizable(&self) -> Result<bool>
pub fn is_maximizable(&self) -> Result<bool>
Gets the window’s native maximize button state
§Platform-specific
- Linux / iOS / Android: Unsupported.
Sourcepub fn is_minimizable(&self) -> Result<bool>
pub fn is_minimizable(&self) -> Result<bool>
Gets the window’s native minimize button state
§Platform-specific
- Linux / iOS / Android: Unsupported.
Sourcepub fn is_closable(&self) -> Result<bool>
pub fn is_closable(&self) -> Result<bool>
Sourcepub fn is_visible(&self) -> Result<bool>
pub fn is_visible(&self) -> Result<bool>
Gets the window’s current visibility state.
Sourcepub fn current_monitor(&self) -> Result<Option<Monitor>>
pub fn current_monitor(&self) -> Result<Option<Monitor>>
Returns the monitor on which the window currently resides.
Returns None if current monitor can’t be detected.
Sourcepub fn primary_monitor(&self) -> Result<Option<Monitor>>
pub fn primary_monitor(&self) -> Result<Option<Monitor>>
Returns the primary monitor of the system.
Returns None if it can’t identify any monitor as a primary one.
Sourcepub fn monitor_from_point(&self, x: f64, y: f64) -> Result<Option<Monitor>>
pub fn monitor_from_point(&self, x: f64, y: f64) -> Result<Option<Monitor>>
Returns the monitor that contains the given point.
Sourcepub fn available_monitors(&self) -> Result<Vec<Monitor>>
pub fn available_monitors(&self) -> Result<Vec<Monitor>>
Returns the list of all the monitors available on the system.
Source§impl<R: Runtime> WebviewWindow<R>
Webview APIs.
impl<R: Runtime> WebviewWindow<R>
Webview APIs.
Sourcepub fn with_webview<F: FnOnce(PlatformWebview) + Send + 'static>(
&self,
f: F,
) -> Result<()>
pub fn with_webview<F: FnOnce(PlatformWebview) + Send + 'static>( &self, f: F, ) -> Result<()>
Executes a closure, providing it with the webview handle that is specific to the current platform.
The closure is executed on the main thread.
Note that webview2-com, webkit2gtk, objc2_web_kit and similar crates may be updated in minor releases of Tauri.
Therefore it’s recommended to pin Tauri to at least a minor version when you’re using with_webview.
§Examples
use tauri::Manager;
fn main() {
tauri::Builder::default()
.setup(|app| {
let main_webview = app.get_webview_window("main").unwrap();
main_webview.with_webview(|webview| {
#[cfg(target_os = "linux")]
{
// see <https://docs.rs/webkit2gtk/2.0.0/webkit2gtk/struct.WebView.html>
// and <https://docs.rs/webkit2gtk/2.0.0/webkit2gtk/trait.WebViewExt.html>
use webkit2gtk::WebViewExt;
webview.inner().set_zoom_level(4.);
}
#[cfg(windows)]
unsafe {
// see <https://docs.rs/webview2-com/0.19.1/webview2_com/Microsoft/Web/WebView2/Win32/struct.ICoreWebView2Controller.html>
webview.controller().SetZoomFactor(4.).unwrap();
}
#[cfg(target_os = "macos")]
unsafe {
let view: &objc2_web_kit::WKWebView = &*webview.inner().cast();
let controller: &objc2_web_kit::WKUserContentController = &*webview.controller().cast();
let window: &objc2_app_kit::NSWindow = &*webview.ns_window().cast();
view.setPageZoom(4.);
controller.removeAllUserScripts();
let bg_color = objc2_app_kit::NSColor::colorWithDeviceRed_green_blue_alpha(0.5, 0.2, 0.4, 1.);
window.setBackgroundColor(Some(&bg_color));
}
#[cfg(target_os = "android")]
{
use jni::objects::JValue;
webview.jni_handle().exec(|env, _, webview| {
env.call_method(webview, "zoomBy", "(F)V", &[JValue::Float(4.)]).unwrap();
})
}
});
Ok(())
});
}Navigates the webview to the defined url.
Sourcepub fn on_message(
self,
request: InvokeRequest,
responder: Box<OwnedInvokeResponder<R>>,
)
pub fn on_message( self, request: InvokeRequest, responder: Box<OwnedInvokeResponder<R>>, )
Handles this window receiving an crate::webview::InvokeRequest.
Sourcepub fn open_devtools(&self)
Available on debug-assertions enabled or crate feature devtools only.
pub fn open_devtools(&self)
devtools only.Opens the developer tools window (Web Inspector).
The devtools is only enabled on debug builds or with the devtools feature flag.
§Platform-specific
- macOS: Only supported on macOS 10.15+. This is a private API on macOS, so you cannot use this if your application will be published on the App Store.
§Examples
use tauri::Manager;
tauri::Builder::default()
.setup(|app| {
#[cfg(debug_assertions)]
app.get_webview_window("main").unwrap().open_devtools();
Ok(())
});Sourcepub fn close_devtools(&self)
Available on debug-assertions enabled or crate feature devtools only.
pub fn close_devtools(&self)
devtools only.Closes the developer tools window (Web Inspector).
The devtools is only enabled on debug builds or with the devtools feature flag.
§Platform-specific
- macOS: Only supported on macOS 10.15+. This is a private API on macOS, so you cannot use this if your application will be published on the App Store.
- Windows: Unsupported.
§Examples
use tauri::Manager;
tauri::Builder::default()
.setup(|app| {
#[cfg(debug_assertions)]
{
let webview = app.get_webview_window("main").unwrap();
webview.open_devtools();
std::thread::spawn(move || {
std::thread::sleep(std::time::Duration::from_secs(10));
webview.close_devtools();
});
}
Ok(())
});Sourcepub fn is_devtools_open(&self) -> bool
Available on debug-assertions enabled or crate feature devtools only.
pub fn is_devtools_open(&self) -> bool
devtools only.Checks if the developer tools window (Web Inspector) is opened.
The devtools is only enabled on debug builds or with the devtools feature flag.
§Platform-specific
- macOS: Only supported on macOS 10.15+. This is a private API on macOS, so you cannot use this if your application will be published on the App Store.
- Windows: Unsupported.
§Examples
use tauri::Manager;
tauri::Builder::default()
.setup(|app| {
#[cfg(debug_assertions)]
{
let webview = app.get_webview_window("main").unwrap();
if !webview.is_devtools_open() {
webview.open_devtools();
}
}
Ok(())
});Sourcepub fn set_zoom(&self, scale_factor: f64) -> Result<()>
pub fn set_zoom(&self, scale_factor: f64) -> Result<()>
Set the webview zoom level
§Platform-specific:
- Android: Not supported.
- macOS: available on macOS 11+ only.
- iOS: available on iOS 14+ only.
Sourcepub fn clear_all_browsing_data(&self) -> Result<()>
pub fn clear_all_browsing_data(&self) -> Result<()>
Clear all browsing data for this webview window.
Returns all cookies in the runtime’s cookie store including HTTP-only and secure cookies.
Note that cookies will only be returned for URLs with an http or https scheme. Cookies set through javascript for local files (such as those served from the tauri://) protocol are not currently supported.
§Stability
The return value of this function leverages tauri_runtime::Cookie which re-exports the cookie crate.
This dependency might receive updates in minor Tauri releases.
§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 reading cookies.
Returns all cookies in the runtime’s cookie store for all URLs including HTTP-only and secure cookies.
Note that cookies will only be returned for URLs with an http or https scheme. Cookies set through javascript for local files (such as those served from the tauri://) protocol are not currently supported.
§Stability
The return value of this function leverages tauri_runtime::Cookie which re-exports the cookie crate.
This dependency might receive updates in minor Tauri releases.
§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 reading cookies.
§Platform-specific
- Android: Unsupported, always returns an empty
Vec.
Trait Implementations§
Source§impl<R: Runtime> Clone for WebviewWindow<R>
impl<R: Runtime> Clone for WebviewWindow<R>
Source§impl<'de, R: Runtime> CommandArg<'de, R> for WebviewWindow<R>
impl<'de, R: Runtime> CommandArg<'de, R> for WebviewWindow<R>
Source§fn from_command(command: CommandItem<'de, R>) -> Result<Self, InvokeError>
fn from_command(command: CommandItem<'de, R>) -> Result<Self, InvokeError>
Grabs the Window from the CommandItem. This will never fail.
Source§impl<R: Runtime> Emitter<R> for WebviewWindow<R>
impl<R: Runtime> Emitter<R> for WebviewWindow<R>
Source§fn emit_str(&self, event: &str, payload: String) -> Result<()>
fn emit_str(&self, event: &str, payload: String) -> Result<()>
Emitter::emit but the payload is json serialized.Source§fn emit_str_to<I>(&self, target: I, event: &str, payload: String) -> Result<()>where
I: Into<EventTarget>,
fn emit_str_to<I>(&self, target: I, event: &str, payload: String) -> Result<()>where
I: Into<EventTarget>,
Emitter::emit_to but the payload is json serialized.Source§fn emit_str_filter<F>(
&self,
event: &str,
payload: String,
filter: F,
) -> Result<()>
fn emit_str_filter<F>( &self, event: &str, payload: String, filter: F, ) -> Result<()>
Emitter::emit_filter but the payload is json serialized.Source§impl<R: Runtime> FunctionArg for WebviewWindow<R>
impl<R: Runtime> FunctionArg for WebviewWindow<R>
Source§impl<R: Runtime> HasDisplayHandle for WebviewWindow<R>
impl<R: Runtime> HasDisplayHandle for WebviewWindow<R>
Source§fn display_handle(&self) -> Result<DisplayHandle<'_>, HandleError>
fn display_handle(&self) -> Result<DisplayHandle<'_>, HandleError>
Source§impl<R: Runtime> HasWindowHandle for WebviewWindow<R>
impl<R: Runtime> HasWindowHandle for WebviewWindow<R>
Source§fn window_handle(&self) -> Result<WindowHandle<'_>, HandleError>
fn window_handle(&self) -> Result<WindowHandle<'_>, HandleError>
Source§impl<R: Runtime> Listener<R> for WebviewWindow<R>
impl<R: Runtime> Listener<R> for WebviewWindow<R>
Source§fn listen<F>(&self, event: impl Into<String>, handler: F) -> EventId
fn listen<F>(&self, event: impl Into<String>, handler: F) -> EventId
Listen to an event on this webview window.
§Examples
use tauri::{Manager, Listener};
tauri::Builder::default()
.setup(|app| {
let webview_window = app.get_webview_window("main").unwrap();
webview_window.listen("component-loaded", move |event| {
println!("window just loaded a component");
});
Ok(())
});Source§fn once<F>(&self, event: impl Into<String>, handler: F) -> EventId
fn once<F>(&self, event: impl Into<String>, handler: F) -> EventId
Listen to an event on this window webview only once.
See Self::listen for more information.
Source§fn unlisten(&self, id: EventId)
fn unlisten(&self, id: EventId)
Unlisten to an event on this webview window.
§Examples
use tauri::{Manager, Listener};
tauri::Builder::default()
.setup(|app| {
let webview_window = app.get_webview_window("main").unwrap();
let webview_window_ = webview_window.clone();
let handler = webview_window.listen("component-loaded", move |event| {
println!("webview_window just loaded a component");
// we no longer need to listen to the event
// we also could have used `webview_window.once` instead
webview_window_.unlisten(event.id());
});
// stop listening to the event when you do not need it anymore
webview_window.unlisten(handler);
Ok(())
});Source§impl<R: Runtime> Manager<R> for WebviewWindow<R>
impl<R: Runtime> Manager<R> for WebviewWindow<R>
Source§fn resources_table(&self) -> MutexGuard<'_, ResourceTable>
fn resources_table(&self) -> MutexGuard<'_, ResourceTable>
Source§fn app_handle(&self) -> &AppHandle<R>
fn app_handle(&self) -> &AppHandle<R>
Source§fn package_info(&self) -> &PackageInfo
fn package_info(&self) -> &PackageInfo
PackageInfo the manager was created with.Source§fn get_window(&self, label: &str) -> Option<Window<R>>
fn get_window(&self, label: &str) -> Option<Window<R>>
unstable only.Source§fn get_focused_window(&self) -> Option<Window<R>>
fn get_focused_window(&self) -> Option<Window<R>>
unstable only.None if there is not any focused window.Source§fn windows(&self) -> HashMap<String, Window<R>>
fn windows(&self) -> HashMap<String, Window<R>>
unstable only.Source§fn get_webview(&self, label: &str) -> Option<Webview<R>>
fn get_webview(&self, label: &str) -> Option<Webview<R>>
unstable only.Source§fn webviews(&self) -> HashMap<String, Webview<R>>
fn webviews(&self) -> HashMap<String, Webview<R>>
unstable only.Source§fn get_webview_window(&self, label: &str) -> Option<WebviewWindow<R>>
fn get_webview_window(&self, label: &str) -> Option<WebviewWindow<R>>
Source§fn webview_windows(&self) -> HashMap<String, WebviewWindow<R>>
fn webview_windows(&self) -> HashMap<String, WebviewWindow<R>>
Source§fn manage<T>(&self, state: T) -> bool
fn manage<T>(&self, state: T) -> bool
state to the state managed by the application. Read moreSource§fn unmanage<T>(&self) -> Option<T>
fn unmanage<T>(&self) -> Option<T>
Source§fn try_state<T>(&self) -> Option<State<'_, T>>
fn try_state<T>(&self) -> Option<State<'_, T>>
T. Read moreSource§fn asset_protocol_scope(&self) -> Scope
fn asset_protocol_scope(&self) -> Scope
Source§fn path(&self) -> &PathResolver<R>
fn path(&self) -> &PathResolver<R>
Source§impl<R: Runtime> PartialEq for WebviewWindow<R>
impl<R: Runtime> PartialEq for WebviewWindow<R>
impl<R: Runtime> Eq for WebviewWindow<R>
Auto Trait Implementations§
impl<R> Freeze for WebviewWindow<R>where
<R as Runtime<EventLoopMessage>>::WindowDispatcher: Freeze,
<R as Runtime<EventLoopMessage>>::Handle: Freeze,
<R as Runtime<EventLoopMessage>>::WebviewDispatcher: Freeze,
impl<R = Wry<EventLoopMessage>> !RefUnwindSafe for WebviewWindow<R>
impl<R> Send for WebviewWindow<R>
impl<R> Sync for WebviewWindow<R>
impl<R> Unpin for WebviewWindow<R>where
<R as Runtime<EventLoopMessage>>::WindowDispatcher: Unpin,
<R as Runtime<EventLoopMessage>>::Handle: Unpin,
<R as Runtime<EventLoopMessage>>::WebviewDispatcher: Unpin,
impl<R = Wry<EventLoopMessage>> !UnwindSafe for WebviewWindow<R>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> HasRawDisplayHandle for Twhere
T: HasDisplayHandle + ?Sized,
impl<T> HasRawDisplayHandle for Twhere
T: HasDisplayHandle + ?Sized,
Source§fn raw_display_handle(&self) -> Result<RawDisplayHandle, HandleError>
fn raw_display_handle(&self) -> Result<RawDisplayHandle, HandleError>
HasDisplayHandle insteadSource§impl<T> HasRawWindowHandle for Twhere
T: HasWindowHandle + ?Sized,
impl<T> HasRawWindowHandle for Twhere
T: HasWindowHandle + ?Sized,
Source§fn raw_window_handle(&self) -> Result<RawWindowHandle, HandleError>
fn raw_window_handle(&self) -> Result<RawWindowHandle, HandleError>
HasWindowHandle instead