A .NET MAUI class library providing an enhanced WebView control with JavaScript interop, navigation events, cookie management, and URL change detection for Android and iOS.
- Execute JavaScript from C# via
EvaluateJavaScriptAsync - Receive JavaScript calls in C# via
invokeCSharpAction(data)bridge - Navigation events:
Navigating,Navigated,WebViewNavigated - URL change detection for SPAs and PWAs via
UrlChanged(addresses dotnet/maui#19232) - Cookie management:
SetCookieAsync,UpdateCookieAsync,RemoveCookieAsync,RemoveAllCookiesAsync - Multi-window / popup support on Android
- Force reload via
Refresh()
| Platform | Minimum OS Version |
|---|---|
| Android | 21.0 |
| iOS | 12.2 |
Target Frameworks:net10.0-android, net10.0-ios (MAUI 10.0.41)
dotnet add package Com.Bnotech.ExtendedWebViewRegister the handler in your MauiProgram.cs:
usingCom.Bnotech.ExtendedWebView;publicstaticclassMauiProgram{publicstaticMauiAppCreateMauiApp(){varbuilder=MauiApp.CreateBuilder();builder.UseMauiApp<App>().UseExtendedWebView();// <-- Add thisreturnbuilder.Build();}}<!-- In your XAML page -->
<controls:ExtWebViewx:Name="webView"Source="https://example.com" />usingCom.Bnotech.ExtendedWebView;Or set the source in code:
webView.Source=newUrlWebViewSource{Url="https://example.com"};varrequest=newEvaluateJavaScriptAsyncRequest("document.title");awaitwebView.EvaluateJavaScriptAsync(request);The control automatically injects a invokeCSharpAction(data) function into every page. Subscribe to the event in C#:
webView.JavaScriptAction+=(sender,e)=>{stringpayload=e.Payload;// Handle the data sent from JavaScript};Then call it from your web page:
invokeCSharpAction("Hello from JavaScript!");webView.Navigating+=(sender,e)=>{// Fires before navigation starts};webView.Navigated+=(sender,e)=>{// Fires after navigation completes};Detects route changes in single-page applications that don't trigger traditional navigation events:
webView.UrlChanged+=(sender,e)=>{stringnewUrl=e.Url;};// Set a cookieawaitwebView.SetCookieAsync(name:"session",value:"abc123",domain:".example.com",path:"/",expires:DateTimeOffset.UtcNow.AddDays(7),isSecure:true,isHttpOnly:true);// Update a cookie (overwrites by name/domain/path)awaitwebView.UpdateCookieAsync(name:"session",value:"newvalue",domain:".example.com",path:"/");// Remove a specific cookieawaitwebView.RemoveCookieAsync("session",".example.com","/");// Remove all cookiesawaitwebView.RemoveAllCookiesAsync();Force a reload of the current source:
webView.Refresh();| Property | Type | Description |
|---|---|---|
Source | WebViewSource | The URL or HTML content to display. Default: about:blank |
| Method | Description |
|---|---|
EvaluateJavaScriptAsync(request) | Executes JavaScript in the WebView |
SetCookieAsync(...) | Sets a cookie in the platform cookie store |
UpdateCookieAsync(...) | Updates (overwrites) an existing cookie |
RemoveCookieAsync(name, domain, path) | Removes a specific cookie |
RemoveAllCookiesAsync() | Removes all cookies |
Refresh() | Forces a reload of the current source |
| Event | EventArgs | Description |
|---|---|---|
JavaScriptAction | JavaScriptActionEventArgs | JS called invokeCSharpAction(data) |
Navigating | WebNavigatingEventArgs | Navigation is about to start |
Navigated | WebNavigatedEventArgs | Navigation completed |
UrlChanged | UrlChangedEventArgs | Displayed URL changed (SPA/PWA) |
SourceChanged | SourceChangedEventArgs | Source property was changed |
See LICENSE.