dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.83k stars 1.67k forks source link

Blazor Hybrid not working on MacOS 15.0 [Potential fix] #23390

Open veler opened 2 days ago

veler commented 2 days ago

Description

Hi,

I believe I found that Blazor Hybrid does not work at all on MacOS 15.0 Beta (Sequoia).

For context, I'm the author of DevToys, which is not a MAUI app, but a AppKit app made in C#, and it use a fork of .NET MAUI's BlazorWebView to work. The app has 300k users on Windows and about 40k on MacOS.

A customer reported that on MacOS 15.0, the app is blank. I do reproduce the issue, and out of curiosity, I tried a new MAUI Blazor Hybrid app to see if the issue reproduces too, and it does, hence my ticket here.

The issue is very easy to reproduce.

Steps to Reproduce

  1. Make sure to run MacOS Sequoia (15.0 Beta)
  2. From VS Code's .NET Maui extension > Create a new .NET MAUI Blazor Hybrid App.
  3. Build and Run on MacOS (desktop).

Expectation: A nice Blazor Hybrid app running

Actual: A bank page image

Early Investigation: It seems like the web browser does not find Blazor. It also seems like the page is about:blank instead of wwwroot/index.html. It seems like somehow BlazorWebView fails to navigate to index.html from app://0.0.0.0.

image

Link to public reproduction project repository

https://github.com/DevToys-app/DevToys

Version with bug

8.0.61 SR6.1

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

Unknown/Other

Affected platforms

macOS, I was not able test on other platforms

Affected platform versions

MacOS 15 Beta (Sequoia)

Did you find any workaround?

Not yet. Will post an update if I find one.

Relevant log output

No response

github-actions[bot] commented 2 days ago

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

veler commented 2 days ago

Further Investigation

Continuing my investigation on DevToys side, I found that StartUrlSchemeTask is never invoked.

A Potential Solution for DevToys and .NET MAUI

After some time, I kind of dumbly decided to change the app host address from 0.0.0.0 to localhost, "just in case", and it worked!

image

I suspect a fix for MAUI is similar. Please try changing this line to app://localhost/ to see if it works.

https://github.com/dotnet/maui/blob/2a9f9fd1980d521d1a36f72febc5ad9f94dc706e/src/BlazorWebView/src/Maui/iOS/BlazorWebViewHandler.iOS.cs#L26C3-L26C83

Consideration

Now I'm concerned with the retro compatibility with older MacOS version. I will try getting out of MacOS 15 Beta and test on MacOS 14.

While my problem is fixed, .NET MAUI Blazor Hybrid still doesn't work at all on MacOS 15, so I will leave this issue open for now and will let you decide what to do with it :-)

marcusbooyah commented 2 days ago

I am seeing the same using MAUI blazor on iOS 18 beta 2 as well.

Bl4d3s commented 2 days ago

We experience the same issue with iOS 18 Beta 2 as well (was working on Beta 1).

A workaround is to set the base url using reflecting as first action in the MauiProgram.cs

var handlerType = typeof(BlazorWebViewHandler);
var field = handlerType.GetField("AppOriginUri", BindingFlags.Static | BindingFlags.NonPublic) ?? throw new Exception("AppOriginUri field not found");
field.SetValue(null, new Uri("app://localhost/"));

Then the app works like before, so I can confirm the above workaround works with Maui Blazor as well.

jfversluis commented 2 days ago

FYI @Eilon @mkArtakMSFT we probably want to fix this before Sept!

nor0x commented 1 day ago

can confirm that this is also an issue on iOS 18 Beta 2 image

I will test the workaround now