Crate wry[][src]

Wry is a Cross-platform WebView rendering library.

There are two main ways to build WebView windows: Application and build by yourself.

Building WebView windows through Application

Application is the recommended way to build the WebView windows. It provides ergonomic and unified APIs across all platforms. To get started, you simply create an Application first:

let application = Application::new()?;

Once you have your application instance, you can create the WebView window by calling Application::add_window. You can provide Attributes and Callback as arguments to configure the WebView window. If you don't have any preference, you could just set them with Default::default() and None.

let attributes = Attributes {
    url: Some("https://www.google.com".to_string()),
    // Initialization scripts can be used to define javascript functions and variables.
    initialization_scripts: vec![
        String::from("breads = NaN"),
        String::from("menacing = 'ゴ'"),
    ],
    ..Default::default()
};
// Callback defines a rust function to be called on javascript side later. Below is a function
// which will print the list of parameters after 8th calls.
let callback = Callback {
    name: "world".to_owned(),
    function: Box::new(|proxy, sequence, requests| {
        // Proxy is like a window handle for you to send message events to the corresponding
        // webview window. You can use it to adjust window and evaluate javascript code like
        // below. This is useful when you want to perform any action in javascript.
        proxy.evaluate_script("console.log(menacing);").unwrap();
        // Sequence is a number counting how many times this function being called.
        if sequence < 8 {
            println!("{} seconds has passed.", sequence);
        } else {
            // Requests is a vector of parameters passed from the caller.
            println!("{:?}", requests);
        }
        0
    }),
};

let window = app.add_window(attributes, Some(vec![callback]))?;

Run the application with run in the end. This will consume the instance and run the application on current thread.

application.run();

Building WebView windows by yourself

If you want to control whole windows creation and events handling, you can use WebViewBuilder / WebView under webview module and platform module to build it all by yourself. platform module re-exports winit for you to build the window across all platforms except Linux. We still need Gtk's library to build the WebView, so it's gtk-rs on Linux.

Modules

platform

Re-export module that provides window creation and event handling based on each platform.

webview

WebView struct and associated types.

Structs

Application

Provides a way to create and manage WebView windows.

ApplicationProxy

A proxy to sent custom messages to Application.

Attributes

Attributes to use when creating a webview window.

Callback

Defines a Rust callback function which can be called on Javascript side.

Icon

An icon used for the window title bar, taskbar, etc.

WindowProxy

A proxy to customize its corresponding WebView window.

Enums

Error

Errors returned by wry.

Message

Describes a general message.

WindowMessage

Describes a message for a WebView window.

Type Definitions

Result

Convinient type alias of Result type for wry.

WindowId