Skip to content

IoTSharp/NativeWebHost

Repository files navigation

NativeWebHost

A .NET WebView host focused on native OS shells.

NuGet License: MIT Build

NativeWebHost lets a .NET application host a web UI inside a native OS shell. The project now keeps one native path per operating system instead of carrying multiple UI-framework-specific shells.

Platform Strategy

OS Window runtime WebView adapter Status
Windows raw Win32 in NativeWebHost.Windows WebView2 in NativeWebHost.Windows Primary path
Linux GTK 3 in NativeWebHost.Linux WebKitGTK in NativeWebHost.Linux Experimental
macOS AppKit in NativeWebHost.Mac WKWebView in NativeWebHost.Mac Experimental
Android Activity in NativeWebHost.Android system WebView in NativeWebHost.Android Experimental

Removed paths: NativeWebHost.WinForms, NativeWebHost.WebView2, and NativeWebHost.Cef. The Windows path is now raw Win32 plus WebView2Aot-based native WebView2, with no WinForms or WPF dependency.

The packaging goal is that end users do not install extra frameworks manually. Windows uses the OS WebView2 runtime or an app-packaged fixed WebView2 runtime. macOS uses system WebKit. Linux should package the needed GTK/WebKitGTK native libraries with the app image/package. Android uses the system WebView and serves app assets from the APK/AAB.

Quick Start

using NativeWebHost;
using NativeWebHost.Windows;

var app = NativeWebApp.CreateBuilder(args)
    .Configure(o =>
    {
        o.Title = "My App";
        o.CustomScheme = "app";
        o.ContentRootPath = Path.Combine(AppContext.BaseDirectory, "wwwroot");
        o.StartUrl = "app://localhost/index.html";
        o.Width = 1280;
        o.Height = 800;
    })
    .UseAdapter(new NativeWebView2AdapterFactory())
    .UseRuntime(new Win32Runtime())
    .Build();

await app.RunAsync();

NativeWebHost.Windows, NativeWebHost.Linux, and NativeWebHost.Mac support app://localhost/... local assets, JavaScript bridge injection, and native window hosting for their platform WebView engines. NativeWebHost.Android provides an Activity base, APK asset loading through https://appassets.androidplatform.net/, JavaScript bridge injection, and same-origin /api/... fetch interception for app-provided handlers.

The samples folder contains adapter samples for Windows, Linux, and macOS. Android is currently consumed through NativeWebHostAndroidActivity.

Features

  • Native host windows with shared runtime/adapter abstractions
  • nativeWeb.invoke(...) and nativeWeb.on(...) JavaScript bridge
  • app://localhost/... local asset loading
  • Android APK/AAB asset loading through the platform WebView
  • Multi-window startup and dynamic window management
  • Splash windows
  • Window style presets such as normal, frameless, DWM blur glass, and VS Code-style chrome where the OS runtime supports them
  • Per-OS adapter samples for Windows, Linux, and macOS

Documentation

Document Description
Getting Started Installation and first app
Architecture Component design and boundaries
JS Bridge C# to JavaScript messaging
Adapters Browser engine adapters
Migration Guide Upgrade notes
Roadmap Release plan

License

MIT - see LICENSE.

About

NativeWebHost lets a .NET application host a web UI inside a native OS shell. The project now keeps one native path per operating system instead of carrying multiple UI-framework-specific shells.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors