Configs2026年5月12日·1 分钟阅读

Wry — Cross-Platform WebView Rendering Library for Rust

A Rust library for creating cross-platform desktop applications with web-based UIs by leveraging each operating system's native webview engine with minimal overhead.

Introduction

Wry is a cross-platform webview rendering library written in Rust that powers the Tauri framework. It provides a unified API for embedding the operating system's native webview engine — WebKit on macOS and Linux, WebView2 on Windows — into Rust desktop applications, enabling developers to build lightweight apps with web-based UIs without bundling a browser engine.

What Wry Does

  • Embeds the system's native webview into a Rust application window on Windows, macOS, and Linux
  • Provides IPC (inter-process communication) between Rust backend code and JavaScript in the webview
  • Supports loading HTML strings, local files, and remote URLs in the webview
  • Handles custom protocol registration for serving local assets via custom URI schemes
  • Integrates with the Tao window management library for cross-platform window creation and event handling

Architecture Overview

Wry abstracts platform-specific webview APIs behind a common Rust interface. On macOS it uses WKWebView via the objc2 crate, on Linux it uses WebKitGTK through gtk-rs bindings, and on Windows it uses the WebView2 COM API. Window management is delegated to Tao, a fork of winit with additional features needed for webview hosting. The IPC bridge serializes messages between the Rust and JavaScript sides using a custom protocol handler, avoiding the overhead of a separate HTTP server.

Self-Hosting & Configuration

  • Add wry and tao to your Cargo.toml dependencies
  • On Linux, install libwebkit2gtk-4.1-dev and libgtk-3-dev as system dependencies
  • On Windows, WebView2 runtime is pre-installed on Windows 10/11; for older systems include the Evergreen bootstrapper
  • Configure webview settings: user agent, custom protocols, dev tools visibility, and transparent backgrounds
  • Use with_ipc_handler() to set up Rust callbacks triggered from JavaScript via window.ipc.postMessage()

Key Features

  • System webview reuse: no bundled Chromium, resulting in tiny binary sizes (typically 2-5 MB)
  • Bidirectional Rust-to-JavaScript IPC for calling native functions from the web UI and vice versa
  • Custom protocol handlers to serve local files and assets without an HTTP server
  • Transparent and decorationless window support for creating custom-shaped UIs
  • Foundation of the Tauri ecosystem, battle-tested in thousands of production Tauri applications

Comparison with Similar Tools

  • Tauri — Full application framework built on top of Wry; Wry is the lower-level webview layer for those who want more control
  • webview (C/C++) — Similar concept in C; Wry is Rust-native with stronger type safety and the Tao event loop
  • Electron — Bundles full Chromium (~150 MB); Wry uses system webviews for a fraction of the size and memory
  • Sciter — Embeddable HTML/CSS renderer; Wry uses real browser engines with full web standards support
  • CEF — Full Chromium embedding; Wry trades Chromium's full API surface for minimal binary size and system integration

FAQ

Q: Is Wry the same thing as Tauri? A: No. Wry is the webview rendering library that Tauri uses under the hood. You can use Wry directly for lower-level control or use Tauri for a complete application framework experience.

Q: Does Wry support all web APIs? A: It supports whatever the platform's webview engine supports. WebView2 on Windows and WebKit on macOS cover most modern web APIs. Linux depends on the installed WebKitGTK version.

Q: Can I use React, Vue, or Svelte with Wry? A: Yes. Build your frontend with any web framework and either bundle the static assets for loading via custom protocols or serve them from a local dev server.

Q: How does Wry handle multi-window applications? A: Wry supports creating multiple webview instances, each attached to its own Tao window, within the same event loop.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产