pub trait WebviewCefExt {
// Required methods
fn send_dev_tools_message(&self, message: &[u8]) -> Result<(), Error>;
fn on_dev_tools_protocol<F: Fn(DevToolsProtocol) + Send + Sync + 'static>(
&self,
f: F,
) -> Result<(), Error>;
fn with_cef_webview<F: FnOnce(&Webview) + Send + 'static>(
&self,
f: F,
) -> Result<(), Error>;
}Expand description
CEF-specific APIs of tauri::Webview and tauri::WebviewWindow.
Required Methods§
Sourcefn send_dev_tools_message(&self, message: &[u8]) -> Result<(), Error>
fn send_dev_tools_message(&self, message: &[u8]) -> Result<(), Error>
Send a message to the DevTools agent. The message should be a UTF-8 encoded JSON string following the Chrome DevTools Protocol format.
Callers share one native request identifier space on this browser, so the
message’s id must come from
allocate_devtools_message_id.
A hardcoded or self-incremented id can collide with a request another
caller already sent, which consumes that producer’s
DevToolsProtocol::MethodResult. The runtime’s own requests are issued
from a reserved range the public allocator never returns, so they cannot
be consumed this way.
§Examples
use tauri::Manager;
use tauri_runtime_cef::{WebviewCefExt, allocate_devtools_message_id};
tauri::Builder::default()
.runtime(tauri_runtime_cef::Cef::default())
.setup(|app| {
let webview = app.get_webview_window("main").unwrap();
// Enable Page domain to receive page lifecycle events
let message_id = allocate_devtools_message_id()?;
let msg = format!(r#"{{"id":{message_id},"method":"Page.enable","params":{{}}}}"#);
webview.send_dev_tools_message(msg.as_bytes())?;
Ok(())
});Sourcefn on_dev_tools_protocol<F: Fn(DevToolsProtocol) + Send + Sync + 'static>(
&self,
f: F,
) -> Result<(), Error>
fn on_dev_tools_protocol<F: Fn(DevToolsProtocol) + Send + Sync + 'static>( &self, f: F, ) -> Result<(), Error>
Register a callback to receive DevTools protocol messages. Messages include both method results and events from the DevTools agent.
The callback observes the whole browser, including requests the runtime and
other callers sent. Match DevToolsProtocol::MethodResult against an
identifier obtained from
allocate_devtools_message_id
instead of assuming every result belongs to this observer.
It is scoped to this webview’s own native browser, so a CEF-owned popup is
a separate browser whose protocol traffic — its page content, its network
activity and its dialog messages — is never reported here; observe popups
through Webview::popups.
§Examples
use tauri::Manager;
use tauri_runtime_cef::{DevToolsProtocol, WebviewCefExt, allocate_devtools_message_id};
tauri::Builder::default()
.runtime(tauri_runtime_cef::Cef::default())
.setup(|app| {
let webview = app.get_webview_window("main").unwrap();
let message_id = allocate_devtools_message_id()?;
webview.on_dev_tools_protocol(move |protocol| {
match protocol {
DevToolsProtocol::Message(msg) => {
if let Ok(s) = std::str::from_utf8(&msg) {
println!("DevTools message: {}", s);
}
}
DevToolsProtocol::Event { method, params } => {
println!("DevTools event: {} {:?}", method, params);
}
// Only this result answers the request sent below.
DevToolsProtocol::MethodResult { message_id: id, success, .. } if id == message_id => {
println!("Page.enable success={}", success);
}
DevToolsProtocol::MethodResult { .. } => {}
}
})?;
let msg = format!(r#"{{"id":{message_id},"method":"Page.enable","params":{{}}}}"#);
webview.send_dev_tools_message(msg.as_bytes())?;
Ok(())
});Sourcefn with_cef_webview<F: FnOnce(&Webview) + Send + 'static>(
&self,
f: F,
) -> Result<(), Error>
fn with_cef_webview<F: FnOnce(&Webview) + Send + 'static>( &self, f: F, ) -> Result<(), Error>
Executes a closure with the CEF platform webview handle, on the CEF UI thread.
See crate::Webview for the native state it exposes, which is sampled
immediately before the closure runs and is not refreshed afterwards.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".