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
22.21k stars 1.75k forks source link

.NET 8: Mac Cat app with WebView not inspectable in Safari Dev Tools #18243

Closed davidbritch closed 2 months ago

davidbritch commented 1 year ago

Description

A .NET 8 Blazor Hybrid app running on Mac Cat is inspectable in Safari Dev tools:

image

This is because there are PRs (https://github.com/dotnet/maui/pull/14610 and https://github.com/dotnet/maui/pull/16631) to re-enable this functionality for BlazorWebView in .NET 8.

However, a .NET 8 MAUI app containing a WebView, running on Mac Cat isn't inspectable in Safari Dev tools:

image

In both apps, the required entitlement is present courtesy of the project templates.

It looks like the same inspectable fix for BlazorWebView needs inserting into WebView.

Steps to Reproduce

  1. Create a new MAUI app using .NET 8.
  2. Build/run on Mac Cat.
  3. Try and inspect the app using Safari Dev Tools. There's no entry for the app.

Link to public reproduction project repository

No response

Version with bug

8.0.0-rc.2.9373

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

7.0.49

Affected platforms

macOS

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

No response

drasticactions commented 1 year ago
       #if MACCATALYST
       Microsoft.Maui.Handlers.WebViewHandler.Mapper.AppendToMapping("Inspect", (handler, view) =>
           {
               if (OperatingSystem.IsMacCatalystVersionAtLeast(16, 4))
               {
                   handler.PlatformView.Inspectable = true;
                   // For older versions .NET Mac Versions that don't include the Inspectable field.
                   // handler.PlatformView.SetValueForKey(Foundation.NSObject.FromObject(true), new Foundation.NSString("inspectable"));
               }
       });
       #endif

You can set it on the webview directly, then it will appear.

https://github.com/drasticactions/MauiRepros/blob/main/MauiWebviewInspect/MauiProgram.cs#L10

スクリーンショット 2023-10-23 20 42 23

For the Blazor View, there's an object for setting the Inspectable setting (https://github.com/drasticactions/maui/blob/0f764ac98e1a0e0e31b797ec991f8bba896a7c9c/src/BlazorWebView/src/SharedSource/BlazorWebViewDeveloperTools.cs#L13) which made adding the flag easy, since setting that field should have already set the flag. For the standard WebView for iOS/Catalyst, it's a bit tougher, since I don't think there is a standard way across all platforms to enable an "inspectable" view. "WKWebView.Inspectable" should be available in .NET 8+ builds, and accessing that to enable it directly on the platform view seems like a fair trade to do it, verses opting for a new public API to do it.

@Eilon Do you have any thoughts on this?

ghost commented 1 year ago

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

Eilon commented 1 year ago

@Eilon Do you have any thoughts on this?

Nothing to add. We could probably do some improvements in general to WebView in the future, perhaps along the lines of what the HybridWebView experiment would add.

kevinxufei commented 2 months ago

I can repro this issue at Maccatalyst platform on the latest 17.6.14 (build 413)(8.0.80 & 8.0.3 & 8.0.0-rc.2.9373), And it also not work on .Net7(7.0.49). After add below workaround, it works fine.

       #if MACCATALYST
       Microsoft.Maui.Handlers.WebViewHandler.Mapper.AppendToMapping("Inspect", (handler, view) =>
         {
             if (OperatingSystem.IsMacCatalystVersionAtLeast(16, 4))
             {
                 handler.PlatformView.Inspectable = true;
                 // For older versions .NET Mac Versions that don't include the Inspectable field.
                 // handler.PlatformView.SetValueForKey(Foundation.NSObject.FromObject(true), new Foundation.NSString("inspectable"));
             }
       });
       #endif
drasticactions commented 2 months ago

@kevinxufei What are you testing? If it's BlazorWebView, that was fixed with https://github.com/dotnet/maui/pull/19909, which was inserted in 8.0.7, so anything newer then that should work fine.

If it's WebView or HybridWebView, those are different and should be turned into a new issue, it's unrelated.

drasticactions commented 2 months ago

Closing due to https://github.com/dotnet/maui/pull/19909

If this is a issue with the newest net8.0 or 9.0 versions, make a new issue.