Skip to content

fix(wasm): Surface exceptions thrown from OnLaunched - #25859

Merged
ramezgerges merged 1 commit into
unoplatform:masterfrom
ramezgerges:dev/rara/wasm-onlaunched-exception
Nov 2, 2026
Merged

ramezgerges merged 1 commit into
unoplatform:masterfrom
ramezgerges:dev/rara/wasm-onlaunched-exception

Conversation

@ramezgerges

Copy link
Copy Markdown
Contributor

GitHub Issue: closes #24308

PR Type:

🐞 Bugfix

What changed? 🚀

On WebAssembly, an exception thrown from Application.OnLaunched left a blank page, a still-visible loader and, without a configured logger, a completely empty console. AppDomain.UnhandledException, TaskScheduler.UnobservedTaskException and a try/catch around await host.RunAsync() all stayed silent.

Cause. Only on the browser, Application.StartPartial defers launch with DispatcherQueue.Main.TryEnqueue(currentApp.PrepareOnLaunched) (so the .NET exports are initialized first). Application.Start returns, WebAssemblyBrowserHost.RunLoop parks on await Task.Delay(-1), and when OnLaunched then throws, NativeDispatcher.RunAction catches it and only calls Log().Error(...), which writes nothing unless the app registered a logger. On the other heads OnLaunched runs synchronously inside Application.Start, so the exception escapes RunLoop and RunAsync faults.

Fix.

  • Application: the deferred launch completes a new internal DeferredLaunch task, or faults it with what PrepareOnLaunched threw (also logged as OnLaunched failed).
  • WebAssemblyBrowserHost.RunLoop awaits DeferredLaunch before parking. A failure goes through the existing catch, which prints App failed to initialize: … with Console.WriteLine (no logger needed) and rethrows, so await host.RunAsync() faults as on the other heads. Secondary-ALC hosts don't wait, as before.

Not covered: AppDomain.UnhandledException is still not raised (the failure reaches the app's await host.RunAsync() instead), and exceptions thrown after the first await of an async void OnLaunched still go through the dispatcher's log-only path.

Validation (runtime: WebAssembly SamplesApp, clean publish, headless Edge, with temporary hooks, not committed: a URL flag that throws from OnLaunched, one that skips logger setup, and the issue's AppDomain/UnobservedTaskException/try-catch probes in Program.cs)

Case master this PR
Throw, no logger (the issue) empty console, RunAsync never completes, no probe fires App failed to initialize: System.InvalidOperationException: boom from OnLaunched with the stack, and the catch around await host.RunAsync() receives it
Throw, logging configured only NativeDispatcher unhandled exception same as above, plus fail: Microsoft.UI.Xaml.Application OnLaunched failed
No throw launches launches

No automated test: the runtime-test app is already launched, so OnLaunched can't be made to throw from a test.

Compile: Uno.UI.Runtime.WebAssembly.Browser (which builds Uno.UI) with analyzers on.

PR Checklist ✅

🤖 Generated with Claude Code

The browser runs OnLaunched from a dispatcher callback after
Application.Start returns, so an exception from it was only logged by
the dispatcher (a no-op without a configured logger) while RunAsync
waited forever: a blank page and an empty console.

The deferred launch now completes a task the host awaits, so the
failure is printed and faults RunAsync, as on the other heads
(fixes unoplatform#24308).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@github-actions github-actions Bot added the platform/wasm 🌐 Categorizes an issue or PR as relevant to the WebAssembly platform label Oct 31, 2026
@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 242603 found UI Test snapshots differences: skia-linux-screenshots: 2458, skia-windows-screenshots: 2458

Details
  • skia-linux-screenshots: 2458 changed over 2492

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AnimatedBackVisualSourceSamplePage.png
    • AnimatedBackVisualSourceSamplePage.png-dark
    • AnimatedVisualsTestbedPage.png
    • AppBarButtonTest.png
    • ApplicationViewSpanningRectsPage.png
    • ApplicationViewSizing.png-dark
    • AppWindowPositionAndSize.png
    • AppWindowFeatures.png-dark
    • Arrange_Performance01.png-dark
    • AppWindowTitleBar Properties.png-dark
    • Attributed_text_Supserscript.png-dark
    • Arrange_Performance01.png
    • AutoBorderStretchwithbottommargin.png
    • Attributed_text_Supserscript.png
    • AutomationPropertiesExtensions_Role.png-dark
    • AutoBorderStretchwithleftmargin.png-dark
    • AutoSizedTopLeft.png-dark
    • AutomationProperties_AutomationId.png-dark
    • AutoSizedTopLeft.png
    • AutomationProperties_AutomationId.png
  • skia-windows-screenshots: 2458 changed over 2492

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Accessibility_ScreenReader.png-dark
    • AndroidWindowInsets.png-dark
    • AndroidWindowInsets.png
    • AnimatedIconPage.png-dark
    • AnimatedVisualsTestbedPage.png-dark
    • AppBarButtonWithIconTest.png
    • AppBar_KeyBoard.png
    • ApplicationViewSpanningRectsPage.png-dark
    • AppWindowClosing.png-dark
    • AppWindowClosing.png
    • ArcSegment.png-dark
    • ArcSegment.png
    • AutoBorderStretchwithbottommargin.png
    • AutoBorderStretchwithleftmargin.png-dark
    • AutomationProperties_Landmark.png
    • AutomationProperties_Name.png-dark
    • AutoSizedTopLeft.png-dark
    • AutoSizedTopLeft.png
    • AutoSuggestBox_Icons.png-dark
    • AutoSuggestBox_Icons.png

@mergify

mergify Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@ramezgerges
ramezgerges merged commit 774b2dc into unoplatform:master Nov 2, 2026
48 checks passed
@ramezgerges
ramezgerges deleted the dev/rara/wasm-onlaunched-exception branch November 2, 2026 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

platform/wasm 🌐 Categorizes an issue or PR as relevant to the WebAssembly platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[WASM] Exceptions thrown from OnLaunched are swallowed, leaving a blank canvas and an empty console

4 participants