windows-webview 0.100.0

Windows WebView2 library
Documentation

windows-webview

Windows WebView wraps the WebView2 COM APIs to host Microsoft Edge (Chromium) in a window.

Start by adding the following to your Cargo.toml file:

[dependencies]
windows-webview = "0.100"
windows-window = "0.100"

WebView2 requires a window and a running message loop. Environment and controller creation complete asynchronously on the UI thread. These constructors pump the message loop until each step finishes.

use windows_webview::*;
use windows_window::{Window, run};

fn main() -> Result<()> {
    let window = Window::new("WebView2").size(1000, 700).create()?;
    let environment = Environment::new()?;
    let controller = environment.create_controller(&window)?;
    let webview = controller.webview()?;

    let (width, height) = window.client_size();
    controller.set_bounds(0, 0, width, height)?;
    webview.navigate("https://github.com/microsoft/windows-rs")?;

    run();
    Ok(())
}

Keep the Controller alive while the browser is hosted.