();
+
+ // Add Linux platform support with all handlers
+ builder.UseLinux();
+
+ return builder.Build();
+ }
+}
diff --git a/WebViewDemo/Pages/WebViewPage.xaml b/WebViewDemo/Pages/WebViewPage.xaml
new file mode 100644
index 0000000..6835202
--- /dev/null
+++ b/WebViewDemo/Pages/WebViewPage.xaml
@@ -0,0 +1,158 @@
+
+
+
+
+
+ #5C6BC0
+ #3949AB
+ #26A69A
+ #667EEA
+ #212121
+ #757575
+ #FFFFFF
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/WebViewDemo/Pages/WebViewPage.xaml.cs b/WebViewDemo/Pages/WebViewPage.xaml.cs
new file mode 100644
index 0000000..a512a9e
--- /dev/null
+++ b/WebViewDemo/Pages/WebViewPage.xaml.cs
@@ -0,0 +1,178 @@
+// WebViewPage - Main page demonstrating WebView with WebKitGTK
+
+using Microsoft.Maui.Controls;
+
+namespace WebViewDemo;
+
+public partial class WebViewPage : ContentPage
+{
+ public WebViewPage()
+ {
+ Console.WriteLine("[WebViewPage] Constructor starting");
+ InitializeComponent();
+
+ // Set initial URL
+ MainWebView.Source = new UrlWebViewSource { Url = "https://dotnet.microsoft.com" };
+
+ Console.WriteLine("[WebViewPage] Constructor finished");
+ }
+
+ private void OnBackClicked(object? sender, EventArgs e)
+ {
+ Console.WriteLine("[WebViewPage] Back button clicked");
+ if (MainWebView.CanGoBack)
+ {
+ MainWebView.GoBack();
+ }
+ }
+
+ private void OnForwardClicked(object? sender, EventArgs e)
+ {
+ Console.WriteLine("[WebViewPage] Forward button clicked");
+ if (MainWebView.CanGoForward)
+ {
+ MainWebView.GoForward();
+ }
+ }
+
+ private void OnReloadClicked(object? sender, EventArgs e)
+ {
+ Console.WriteLine("[WebViewPage] Reload button clicked");
+ MainWebView.Reload();
+ }
+
+ private void OnGoClicked(object? sender, EventArgs e)
+ {
+ Navigate();
+ }
+
+ private void OnUrlSubmitted(object? sender, EventArgs e)
+ {
+ Navigate();
+ }
+
+ private void Navigate()
+ {
+ var url = UrlEntry.Text?.Trim();
+ if (string.IsNullOrEmpty(url))
+ return;
+
+ // Add https:// if not present
+ if (!url.StartsWith("http://") && !url.StartsWith("https://"))
+ url = "https://" + url;
+
+ Console.WriteLine($"[WebViewPage] Navigating to: {url}");
+ MainWebView.Source = new UrlWebViewSource { Url = url };
+ UrlEntry.Text = url;
+ }
+
+ private void OnNavigating(object? sender, WebNavigatingEventArgs e)
+ {
+ StatusLabel.Text = $"Loading: {e.Url}";
+ Console.WriteLine($"[WebViewPage] Navigating to: {e.Url}");
+ }
+
+ private void OnNavigated(object? sender, WebNavigatedEventArgs e)
+ {
+ StatusLabel.Text = e.Result == WebNavigationResult.Success
+ ? $"Loaded: {e.Url}"
+ : $"Failed: {e.Result}";
+
+ UrlEntry.Text = e.Url;
+ Console.WriteLine($"[WebViewPage] Navigated: {e.Result} - {e.Url}");
+ }
+
+ private void OnLoadHtmlClicked(object? sender, EventArgs e)
+ {
+ Console.WriteLine("[WebViewPage] Load HTML button clicked");
+
+ var html = @"
+
+
+
+ OpenMaui WebView
+
+
+
+ Hello from OpenMaui Linux!
+ This HTML content is rendered by WebKitGTK inside your .NET MAUI application.
+
+
+
WebView Features:
+
+ - Full HTML5 support
+ - CSS3 animations and transitions
+ - JavaScript execution
+ - Navigation history (back/forward)
+ - WebGL and canvas support
+
+
+
+
+
+
+ Powered by WebKitGTK - the same engine used by GNOME Web (Epiphany)
+
+
+";
+
+ MainWebView.Source = new HtmlWebViewSource { Html = html };
+ StatusLabel.Text = "Loaded custom HTML";
+ }
+
+ private async void OnEvalJsClicked(object? sender, EventArgs e)
+ {
+ Console.WriteLine("[WebViewPage] Run JS button clicked");
+
+ try
+ {
+ var result = await MainWebView.EvaluateJavaScriptAsync("document.title");
+ StatusLabel.Text = $"JS Result: {result ?? "(null)"}";
+ Console.WriteLine($"[WebViewPage] JS Eval result: {result}");
+ }
+ catch (Exception ex)
+ {
+ StatusLabel.Text = $"JS Error: {ex.Message}";
+ Console.WriteLine($"[WebViewPage] JS Error: {ex.Message}");
+ }
+ }
+}
diff --git a/WebViewDemo/Program.cs b/WebViewDemo/Program.cs
index 289dd7c..4066fc1 100644
--- a/WebViewDemo/Program.cs
+++ b/WebViewDemo/Program.cs
@@ -1,283 +1,67 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
+// Program.cs - Linux platform entry point
-using Microsoft.Maui;
-using Microsoft.Maui.Controls;
-using Microsoft.Maui.Hosting;
using Microsoft.Maui.Platform.Linux;
-using Microsoft.Maui.Platform.Linux.Hosting;
namespace WebViewDemo;
-public static class MauiProgram
+class Program
{
- public static MauiApp CreateMauiApp()
+ static void Main(string[] args)
{
- var builder = MauiApp.CreateBuilder();
- builder.UseMauiApp();
- builder.UseLinux();
- return builder.Build();
- }
-}
+ // Redirect console output to a log file for debugging
+ var logPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "webviewdemo.log");
+ using var logWriter = new StreamWriter(logPath, append: false) { AutoFlush = true };
+ var multiWriter = new MultiTextWriter(Console.Out, logWriter);
+ Console.SetOut(multiWriter);
+ Console.SetError(multiWriter);
-public static class Program
-{
- public static void Main(string[] args)
- {
- Console.WriteLine("[Program] Starting WebView Demo");
-
- var app = MauiProgram.CreateMauiApp();
- LinuxApplication.Run(app, args);
- }
-}
-
-public class App : Application
-{
- public App()
- {
- MainPage = new NavigationPage(new WebViewPage())
+ // Global exception handler
+ AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
{
- Title = "WebView Demo"
- };
- }
-}
-
-public class WebViewPage : ContentPage
-{
- private readonly WebView _webView;
- private readonly Entry _urlEntry;
- private readonly Label _statusLabel;
-
- public WebViewPage()
- {
- Title = "WebView Demo";
-
- _webView = new WebView
- {
- HeightRequest = 400,
- VerticalOptions = LayoutOptions.Fill,
- HorizontalOptions = LayoutOptions.Fill,
- Source = new UrlWebViewSource { Url = "https://dotnet.microsoft.com" }
- };
-
- _webView.Navigating += OnNavigating;
- _webView.Navigated += OnNavigated;
-
- _urlEntry = new Entry
- {
- Placeholder = "Enter URL...",
- Text = "https://dotnet.microsoft.com",
- HorizontalOptions = LayoutOptions.Fill
- };
- _urlEntry.Completed += OnUrlSubmitted;
-
- _statusLabel = new Label
- {
- Text = "Ready",
- TextColor = Colors.Gray,
- FontSize = 12
- };
-
- var goButton = new Button
- {
- Text = "Go",
- WidthRequest = 60
- };
- goButton.Clicked += (s, e) => Navigate();
-
- var backButton = new Button
- {
- Text = "Back",
- WidthRequest = 60
- };
- backButton.Clicked += (s, e) => _webView.GoBack();
-
- var forwardButton = new Button
- {
- Text = "Forward",
- WidthRequest = 80
- };
- forwardButton.Clicked += (s, e) => _webView.GoForward();
-
- var reloadButton = new Button
- {
- Text = "Reload",
- WidthRequest = 70
- };
- reloadButton.Clicked += (s, e) => _webView.Reload();
-
- var loadHtmlButton = new Button
- {
- Text = "Load HTML",
- WidthRequest = 100
- };
- loadHtmlButton.Clicked += OnLoadHtmlClicked;
-
- var evalJsButton = new Button
- {
- Text = "Run JS",
- WidthRequest = 80
- };
- evalJsButton.Clicked += OnEvalJsClicked;
-
- // Navigation bar
- var navBar = new HorizontalStackLayout
- {
- Spacing = 5,
- Children = { backButton, forwardButton, reloadButton }
- };
-
- // URL bar
- var urlBar = new HorizontalStackLayout
- {
- Spacing = 5,
- Children = { _urlEntry, goButton }
- };
-
- // Action buttons
- var actionBar = new HorizontalStackLayout
- {
- Spacing = 5,
- Children = { loadHtmlButton, evalJsButton }
- };
-
- Content = new VerticalStackLayout
- {
- Padding = 10,
- Spacing = 10,
- Children =
+ var ex = e.ExceptionObject as Exception;
+ Console.WriteLine($"[FATAL] Unhandled exception: {ex?.GetType().Name}: {ex?.Message}");
+ Console.WriteLine($"[FATAL] Stack trace: {ex?.StackTrace}");
+ if (ex?.InnerException != null)
{
- new Label { Text = "WebView Demo - WebKitGTK", FontSize = 20, FontAttributes = FontAttributes.Bold },
- navBar,
- urlBar,
- _webView,
- actionBar,
- _statusLabel
+ Console.WriteLine($"[FATAL] Inner exception: {ex.InnerException.GetType().Name}: {ex.InnerException.Message}");
+ Console.WriteLine($"[FATAL] Inner stack trace: {ex.InnerException.StackTrace}");
}
};
- }
- private void Navigate()
- {
- var url = _urlEntry.Text?.Trim();
- if (string.IsNullOrEmpty(url))
- return;
+ TaskScheduler.UnobservedTaskException += (sender, e) =>
+ {
+ Console.WriteLine($"[FATAL] Unobserved task exception: {e.Exception?.GetType().Name}: {e.Exception?.Message}");
+ Console.WriteLine($"[FATAL] Stack trace: {e.Exception?.StackTrace}");
+ e.SetObserved(); // Prevent crash
+ };
- // Add https:// if not present
- if (!url.StartsWith("http://") && !url.StartsWith("https://"))
- url = "https://" + url;
+ Console.WriteLine($"[Program] Starting WebView Demo at {DateTime.Now}");
+ Console.WriteLine($"[Program] Log file: {logPath}");
- _webView.Source = new UrlWebViewSource { Url = url };
- _urlEntry.Text = url;
- }
-
- private void OnUrlSubmitted(object? sender, EventArgs e)
- {
- Navigate();
- }
-
- private void OnNavigating(object? sender, WebNavigatingEventArgs e)
- {
- _statusLabel.Text = $"Loading: {e.Url}";
- Console.WriteLine($"[WebViewPage] Navigating to: {e.Url}");
- }
-
- private void OnNavigated(object? sender, WebNavigatedEventArgs e)
- {
- _statusLabel.Text = e.Result == WebNavigationResult.Success
- ? $"Loaded: {e.Url}"
- : $"Failed: {e.Result}";
-
- _urlEntry.Text = e.Url;
- Console.WriteLine($"[WebViewPage] Navigated: {e.Result} - {e.Url}");
- }
-
- private void OnLoadHtmlClicked(object? sender, EventArgs e)
- {
- var html = @"
-
-
-
- OpenMaui WebView
-
-
-
- Hello from OpenMaui Linux!
- This HTML content is rendered by WebKitGTK inside your .NET MAUI application.
-
-
-
WebView Features:
-
- - Full HTML5 support
- - CSS3 animations and transitions
- - JavaScript execution
- - Navigation history (back/forward)
- - WebGL and canvas support
-
-
-
-
-
-
- Powered by WebKitGTK - the same engine used by GNOME Web (Epiphany)
-
-
-";
-
- _webView.Source = new HtmlWebViewSource { Html = html };
- _statusLabel.Text = "Loaded custom HTML";
- }
-
- private async void OnEvalJsClicked(object? sender, EventArgs e)
- {
try
{
- var result = await _webView.EvaluateJavaScriptAsync("document.title");
- _statusLabel.Text = $"JS Result: {result ?? "(null)"}";
- Console.WriteLine($"[WebViewPage] JS Eval result: {result}");
+ // Create the MAUI app with all handlers registered
+ var app = MauiProgram.CreateMauiApp();
+
+ // Run on Linux platform
+ LinuxApplication.Run(app, args);
}
catch (Exception ex)
{
- _statusLabel.Text = $"JS Error: {ex.Message}";
+ Console.WriteLine($"[FATAL] Exception in Main: {ex.GetType().Name}: {ex.Message}");
+ Console.WriteLine($"[FATAL] Stack trace: {ex.StackTrace}");
+ throw;
}
}
}
+
+// Helper to write to both console and file
+class MultiTextWriter : TextWriter
+{
+ private readonly TextWriter[] _writers;
+ public MultiTextWriter(params TextWriter[] writers) => _writers = writers;
+ public override System.Text.Encoding Encoding => System.Text.Encoding.UTF8;
+ public override void Write(char value) { foreach (var w in _writers) w.Write(value); }
+ public override void WriteLine(string? value) { foreach (var w in _writers) w.WriteLine(value); }
+ public override void Flush() { foreach (var w in _writers) w.Flush(); }
+}
diff --git a/WebViewDemo/WebViewDemo.csproj b/WebViewDemo/WebViewDemo.csproj
index beca1f9..4d84e80 100644
--- a/WebViewDemo/WebViewDemo.csproj
+++ b/WebViewDemo/WebViewDemo.csproj
@@ -5,14 +5,11 @@
net9.0
enable
enable
- WebViewDemo
- linux-arm64
- true
- false
+ true
-
+