Rust Webkit2GTK Ping Pong Example

This page summarizes the projects mentioned and recommended in the original post on /r/rust

Our great sponsors
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • SaaSHub - Software Alternatives and Reviews
  • webkit2gtk-rs

    Discontinued [UNMAINTAINED] WebKit2 bindings and wrappers for Rust

  • I am creating a desktop app based on webkit2gtk-rs. I am having a problem with sending data back to the UI after calling:

  • web-view

    Rust bindings for webview, a tiny cross-platform library to render web-based GUIs for desktop applications

  • I want get a pong back from the app process, but I cant figure out how. I do aware of Boscop Webview and webview_official, but I want to work with Webkit2GTK to have more controls. I really appreciate your kind help.

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

    InfluxDB logo
  • webview_rust

    [wip] Rust Bindings to webview

  • I want get a pong back from the app process, but I cant figure out how. I do aware of Boscop Webview and webview_official, but I want to work with Webkit2GTK to have more controls. I really appreciate your kind help.

  • crates.io

    The Rust package registry

  • use glib::{self, ObjectExt, ToValue, ToVariant}; use gtk::{ traits::{ContainerExt, WidgetExt}, Inhibit, Window, WindowType, }; use webkit2gtk::traits::{SettingsExt, UserContentManagerExt, WebViewExt}; use webkit2gtk::{self, UserContentManager, WebContext, WebView, WebViewExtManual}; fn main() { gtk::init().unwrap(); let window = Window::new(WindowType::Toplevel); let context = WebContext::default().unwrap(); let ucm = UserContentManager::new(); let webview = WebView::new_with_context_and_user_content_manager(&context, &ucm); webview.load_uri("https://crates.io/"); window.add(&webview); let settings = WebViewExt::settings(&webview).unwrap(); settings.set_enable_developer_extras(true); window.show_all(); webview .user_content_manager() .unwrap() .register_script_message_handler("external"); webview .user_content_manager() .unwrap() .connect_script_message_received(Some("external"), move |ucm, jsr| { let ctx = jsr.global_context().unwrap(); let val = jsr.value().unwrap(); let msg = val.to_string(&ctx).unwrap(); match msg.as_str() { "ping" => { println!("A ping received "); // I want to response a pong back } _ => {} } }); window.connect_delete_event(|_, _| { gtk::main_quit(); Inhibit(false) }); gtk::main(); }

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts