34 releases (breaking)

0.28.0 Nov 17, 2023
0.26.0 Aug 30, 2023
0.25.0 May 11, 2023
0.23.0 Feb 17, 2023
0.7.0 Nov 9, 2021

#40 in Windows APIs

Download history 13473/week @ 2023-11-07 14690/week @ 2023-11-14 12374/week @ 2023-11-21 12297/week @ 2023-11-28 13750/week @ 2023-12-05 12598/week @ 2023-12-12 10928/week @ 2023-12-19 9250/week @ 2023-12-26 10595/week @ 2024-01-02 11618/week @ 2024-01-09 12456/week @ 2024-01-16 11443/week @ 2024-01-23 13477/week @ 2024-01-30 11391/week @ 2024-02-06 14265/week @ 2024-02-13 13422/week @ 2024-02-20

54,340 downloads per month
Used in 143 crates (12 directly)

MIT license

83K SLoC


This crate implements Rust bindings for the WebView2 COM APIs, as well as several important Win32 APIs necessary to build a standalone GUI application hosting WebView2. The bindings are generated by the Windows crate in webview2-com-sys.

Getting Started

Include a reference to webview2-com in your Cargo.toml:

webview2-com = "0.28.0"

See the docs or take a look at the sample.rs example (adapted from microsoft/windows-samples-rs) for more details.


Most of the bindings are re-exported transparently from webview2-com-sys, and they are still marked unsafe. Unlike typical idiomatic Rust crates wrapped around a -sys crate, the emphasis of this crate is on writing as little manual wrapper code as possible. This way, webview2-com can project 100% of the WebView2 COM API, but the downside is you will need to wrap most uses in an unsafe block or function.

Convenience Types

Most of the code added by this crate consists of convenience types to implement COM interfaces that are required for callbacks and setting options:

  • callback.rs: Implements all of the event sink handler interfaces used by WebView2.
  • options.rs: Implements the ICoreWebView2EnvironmentOptions interface which is passed to CreateCoreWebView2EnvironmentWithOptions if you want to customize the environment.

There are also some utilities for dealing with PWSTR in/out-params that may be useful:

  • pwstr.rs: string_from_pcwstr, take_pwstr, and pwstr_from_str.

Windows Metadata

The Windows crate requires a Windows Metadata (winmd) file describing the API. The one used in this crate was generated with the webview2-win32md project. This crate needs it to use the #[implement] macro from the Windows crate.


~2.5M SLoC