#yew #web-view


2-way communcation bridge between web-view and yew

1 unstable release

0.1.0 May 3, 2020

#126 in #yew


218 lines

yew_webview_bridge - 2-way communcation between yew and web-view

This crate provides a 2-way communcation bridge between web-view and yew.

For the frontend, it provides a yew service (WebViewMessageService), with which components can easily send (and receive matching responses) to web-view.

For the backend, it provides an easy handler that can be used to respond to messages from the frontend.

Internally, unique random IDs are generated for every service and message, so that responses can be matched up with the correct component and message.


The crate has to be included in both the frontend crate (the one with yew) and the backend/host crate (the one with web-view), with the appropriate feature flags.

Frontend crate

yew_webview_bridge = { version = "0.1.0", features = ["frontend"] }

Backend crate

yew_webview_bridge = { version = "0.1.0", features = ["backend"] }


Frontend (yew)

use yew_webview_bridge::frontend::*;

pub struct MyComponent {
  webview: WebViewMessageService,
  // .. other fields

// In one of the components methods (e.g. update)
        .send_message(self.state.value.clone()) // The value you want to send
        .map(|res: String| Msg::AddStr(res)), // Mapping the result to a component Msg

Backend (web-view)

use yew_webview_bridge::backend::*;

    // all the other options
    .invoke_handler(|webview, arg| {
        handle_yew_message(webview, arg, |message: String| {
            // If we return a Some(_), we send a response for this message
            Some(format!("Hello, {}", &message))


A large chunk of inspiration was taken from the discussion about the issue, and the resulting example repository by @mbuscemi. Thanks go out to everyone involved!


Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


~80K SLoC