Skip to main content

WebviewBridge

Trait WebviewBridge 

Source
pub trait WebviewBridge: Send + Sync {
Show 19 methods // Required methods fn eval_webview( &self, label: Option<&str>, script: &str, ) -> Result<(), String>; fn get_window_states(&self, label: Option<&str>) -> Vec<WindowState>; fn list_window_labels(&self) -> Vec<String>; fn get_native_handle(&self, label: Option<&str>) -> Result<isize, String>; fn manage_window( &self, label: Option<&str>, action: &str, ) -> Result<String, String>; fn resize_window( &self, label: Option<&str>, width: u32, height: u32, ) -> Result<(), String>; fn move_window( &self, label: Option<&str>, x: i32, y: i32, ) -> Result<(), String>; fn set_window_title( &self, label: Option<&str>, title: &str, ) -> Result<(), String>; // Provided methods fn try_get_window_states( &self, label: Option<&str>, ) -> Result<Vec<WindowState>, String> { ... } fn try_list_window_labels(&self) -> Result<Vec<String>, String> { ... } fn eval_webview_resolved( &self, label: Option<&str>, script: &str, ) -> Result<String, String> { ... } fn native_type_text( &self, _label: Option<&str>, _text: &str, ) -> Result<(), String> { ... } fn native_key(&self, _label: Option<&str>, _key: &str) -> Result<(), String> { ... } fn native_click( &self, _label: Option<&str>, _x: f64, _y: f64, ) -> Result<(), String> { ... } fn app_data_dir(&self) -> Result<PathBuf, String> { ... } fn app_config_dir(&self) -> Result<PathBuf, String> { ... } fn app_log_dir(&self) -> Result<PathBuf, String> { ... } fn app_local_data_dir(&self) -> Result<PathBuf, String> { ... } fn tauri_config(&self) -> Value { ... }
}
Expand description

Runtime-erased interface for webview and backend access, allowing the MCP server to interact with Tauri windows and the application backend without generic parameters.

Victauri implements this for tauri::AppHandle; it is public so tests (and embedders) can supply a mock. Stability contract: any method added to this trait in a future release will have a default implementation, so implementing it does not pin you to an exact version. WindowState is #[non_exhaustive] — build one with WindowState::new(label).with_*(..).

Required Methods§

Source

fn eval_webview(&self, label: Option<&str>, script: &str) -> Result<(), String>

Execute JavaScript in the target webview (defaults to “main” or first visible window).

§Errors

Returns an error string if no matching window is found or the eval fails.

Source

fn get_window_states(&self, label: Option<&str>) -> Vec<WindowState>

Retrieve the state of one or all windows (position, size, visibility, focus, URL).

Source

fn list_window_labels(&self) -> Vec<String>

Return the labels of all open webview windows.

Source

fn get_native_handle(&self, label: Option<&str>) -> Result<isize, String>

Return the platform-native window handle for screenshot capture. Windows: HWND, macOS: CGWindowID (window number), Linux: X11 window ID.

§Errors

Returns an error string if no matching window is found or the handle type is unsupported.

Source

fn manage_window( &self, label: Option<&str>, action: &str, ) -> Result<String, String>

Perform a window management action (minimize, maximize, close, show, hide, etc.).

§Errors

Returns an error string if no matching window is found or the action fails.

Source

fn resize_window( &self, label: Option<&str>, width: u32, height: u32, ) -> Result<(), String>

Set the logical size of a window in device-independent pixels.

§Errors

Returns an error string if no matching window is found or the resize fails.

Source

fn move_window(&self, label: Option<&str>, x: i32, y: i32) -> Result<(), String>

Set the logical position of a window in device-independent pixels.

§Errors

Returns an error string if no matching window is found or the move fails.

Source

fn set_window_title( &self, label: Option<&str>, title: &str, ) -> Result<(), String>

Set the title bar text of a window.

§Errors

Returns an error string if no matching window is found or the title change fails.

Provided Methods§

Source

fn try_get_window_states( &self, label: Option<&str>, ) -> Result<Vec<WindowState>, String>

Like get_window_states, but distinguishes “could not ask” (the UI thread did not answer in time) from “no such window”. A caller that reports a window as missing, or a list as empty, must use this.

§Errors

Returns an error string if the window states could not be obtained.

Source

fn try_list_window_labels(&self) -> Result<Vec<String>, String>

Like list_window_labels, but distinguishes “could not ask” (e.g. the UI thread did not answer in time) from “there are no windows”. A caller deciding that a window is GONE must use this — an empty list from a wedged UI is not evidence of anything.

§Errors

Returns an error string if the window list could not be obtained.

Source

fn eval_webview_resolved( &self, label: Option<&str>, script: &str, ) -> Result<String, String>

Like eval_webview, but returns the label of the window the script was actually delivered to (for None, the resolved default window). The default implementation returns the requested label, or an EMPTY string when it cannot know which window a None label resolved to — callers must treat empty as “unknown”.

§Errors

Returns an error string if no matching window is found or the eval fails.

Source

fn native_type_text( &self, _label: Option<&str>, _text: &str, ) -> Result<(), String>

Type Unicode text as trusted OS keyboard input into the focused element of the target window. The element must already hold focus.

§Errors

Returns an error if not supported on this platform or the window is missing.

Source

fn native_key(&self, _label: Option<&str>, _key: &str) -> Result<(), String>

Press a single named key (e.g. Enter, Tab, Escape, ArrowDown) as trusted OS keyboard input to the focused element of the target window.

§Errors

Returns an error if not supported on this platform or the key is unknown.

Source

fn native_click( &self, _label: Option<&str>, _x: f64, _y: f64, ) -> Result<(), String>

Click at logical (CSS-pixel) coordinates within the target window’s content area, as a trusted OS mouse event.

§Errors

Returns an error if not supported on this platform or the window is missing.

Source

fn app_data_dir(&self) -> Result<PathBuf, String>

Return the app’s per-user data directory (e.g. ~/.local/share/<app>/).

§Errors

Returns an error if the path cannot be resolved.

Source

fn app_config_dir(&self) -> Result<PathBuf, String>

Return the app’s per-user config directory (e.g. ~/.config/<app>/).

§Errors

Returns an error if the path cannot be resolved.

Source

fn app_log_dir(&self) -> Result<PathBuf, String>

Return the app’s log directory.

§Errors

Returns an error if the path cannot be resolved.

Source

fn app_local_data_dir(&self) -> Result<PathBuf, String>

Return the app’s local data directory.

§Errors

Returns an error if the path cannot be resolved.

Source

fn tauri_config(&self) -> Value

Return the Tauri app configuration as JSON.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<R: Runtime> WebviewBridge for AppHandle<R>

Implementors§