Skip to main content

WebViewDelegate

Trait WebViewDelegate 

Source
pub trait WebViewDelegate: Send + Sync {
    // Required methods
    fn on_page_started(&self);
    fn on_page_finished(&self);
    fn handle_post_message(&self, msg: String);
    fn log(&self, level: LogLevel, message: &str);

    // Provided methods
    fn on_load_error(&self, _error: &LoadError) { ... }
    fn on_title_changed(&self, _title: &str) { ... }
    fn on_favicon_changed(&self, _png_bytes: Vec<u8>) { ... }
    fn handle_native_component_message(&self, message_json: &str) { ... }
}
Expand description

WebView delegate trait - focused on WebView events only

Required Methods§

Source

fn on_page_started(&self)

Called when the page starts loading

Source

fn on_page_finished(&self)

Called when the page finishes loading

Source

fn handle_post_message(&self, msg: String)

Handles a postMessage from the page View(WebView)

Source

fn log(&self, level: LogLevel, message: &str)

Receive log from WebView

Provided Methods§

Source

fn on_load_error(&self, _error: &LoadError)

Called when a main-frame page load fails (e.g. DNS failure, network unreachable, TLS error).

Only fires for the main document; sub-resource errors are ignored. Default is a no-op so existing implementations do not need to change.

Source

fn on_title_changed(&self, _title: &str)

Called when the document title changes (where the platform reports it; currently Windows/WebView2). Default is a no-op so existing implementations do not need to change.

Source

fn on_favicon_changed(&self, _png_bytes: Vec<u8>)

Called when the page favicon changes (where the platform reports it; currently Windows/WebView2). png_bytes holds the favicon encoded as PNG; an empty vector means the page has no favicon. Default is a no-op so existing implementations do not need to change.

Source

fn handle_native_component_message(&self, message_json: &str)

Handles a native-component message posted by the page through the embedded-component channel (window.NativeComponentBridge), where the platform routes it in-process (currently Windows/WebView2). message_json is the raw component message (component.mount, component.update, …). Default is a no-op so existing implementations do not need to change.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§