Skip to content

A minimal .NET wrapper around WebView2. No UI framework, just a Win32 message loop

License

Notifications You must be signed in to change notification settings

rgwood/MinimalWebView

Repository files navigation

MinimalWebView

build

A tiny .NET 6 Windows application that hosts web UI in WebView2. No UI framework, just a plain old Win32 message loop.

image

This is very bare-bones and is mostly useful as an educational example. If you're looking for more functionality, my MaximalWebView builds on top of this.

Motivation

This is an experiment to see how far I can push a slim Windows application that uses C# for the hosting logic and web UI for the "front-end".

The native UI situation on Windows is a little bleak and WebView2 ships with Windows 11, so it's a good time to lean into web UI a little more. But... the .NET team has been killing it recently, I'd like to write my code that lives outside Chromium in C# or F#.

Microsoft provides WinForms and WPF wrappers for WebView2, so I could embed web UI in a plain old .NET GUI app. But WinForms and WPF are big dependencies and they're mostly unnecessary for web UI. Why not see how far we can get with an old-school Win32 message pump?

Dependencies

Microsoft.Web.WebView2.Core to interact with WebView2, and CsWin32 to generate bindings to native Windows APIs (at compile time only).

Known Issues

The resulting application cannot currently be trimmed because of the way Microsoft.Web.WebView2.Core does COM interop. Please upvote this issue.

Credits

Initially derived from Vítězslav Imrýšek's handy CsWin32Playground, where he shows how to create a message pump using CsWin32.

About

A minimal .NET wrapper around WebView2. No UI framework, just a Win32 message loop

Resources

License

Stars

Watchers

Forks

Packages

No packages published