question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MAUI WebView doesn't allow to web session to inspected in Safari developer tools (Mac Catalyst)

See original GitHub issue

Description

WKWebView Safari developer tools (inspect option) are not available in a MAUI Mac app. If the same app is created using native tooling Xcode + Swift with no extra configuration/entitlements - it works (there is a visible session to inspect in Safari dev tools). If a new MAUI app is created with just a WebView in it (which created WKMauiWebView, which is essentially the same as WKWebView), Safari shows no debuggable sessions available.

Other scenarios tests - the same result with no option to debug the session:

  • BlazorWebView
  • Plain MacCatalyst WKWebView
  • MAUI WebView with custom handler with developerExtrasEnabled set

The source for all foud projects is in the following repository: https://github.com/xamcat/maui-wkwebview-inspect

Steps to Reproduce

  1. Create new MAUI App
  2. Register WebView on the main page
 <WebView Source="https://www.apple.com"
             VerticalOptions="FillAndExpand"
             HorizontalOptions="FillAndExpand" />
  1. Run on Mac with dotnet build -t:Run -f net6.0-maccatalyst
  2. Open Safari and navigate to Develop-> <MacName>

Result: No inspectable application message Expected: Web session created by WebView (WKWebView) is visible in debug tools

safari-debug-native-mac-app safari-debug-maui-mac-app safari-debug-maccat-mac-app safari-debug-blazor-mac-app

Version with bug

6.0 (current)

Last version that worked well

Release Candidate 3 (current)

Affected platforms

macOS

Affected platform versions

maccatalyst 13.1

Did you find any workaround?

No workaround has been found.

Relevant log output

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:39 (16 by maintainers)

github_iconTop GitHub Comments

3reactions
tstephansencommented, May 3, 2023

@headintheclouds21 I think I got it figured out. I haven’t actually tested and JS in it yet (busy on another project) but it at least shows up in Safari so I suspect JS debugging will work.

So what I did was create a project with the default maui blazor template. I also made the changes outlined in the PR that fixed this issue. The trick to getting this to work (for me at least) is adding the following to the MainPage.xaml.cs file.

public MainPage()
{
    InitializeComponent();
    Loaded += MainPage_Loaded;
}

private void MainPage_Loaded(object sender, EventArgs e)
{
    if (blazorWebView.Handler.PlatformView is WKWebView view)
    {
        view.SetValueForKey(NSObject.FromObject(true), new NSString("inspectable"));
    }
}

Once I did that the app shows up in Safari again.

CleanShot 2023-05-03 at 13 48 48@2x

3reactions
alexeystrakhcommented, Jun 3, 2022

I found some confirmations that the entitlement is needed (get-task-allow) to have the Safari inspect tools work, but also confirmed that Xcode doesn’t include any entitlements for a Cocoa app and it works for Xcode.

May be Xcode includes this entitlements for debug builds automatically without asking us? Found here

get-task-allow is typically added by Xcode automatically for development builds

Read more comments on GitHub >

github_iconTop Results From Across the Web

WebView - .NET MAUI
This article explains how to use the .NET MAUI WebView to display remote web pages, local HTML files, and HTML strings.
Read more >
How to enable developer tools in MAUI
Enable the Web-Inspector option. To do so: Go to Settings > Safari > Scroll down to the bottom > Open Advanced Menu>Turn on...
Read more >
Inspect WebView in Mac Application
Hello,. What is the proper way to inspect a WebView in a Mac application? I can access any iOS simulator or connected device...
Read more >
Themes of .NET
Maui Blazor template lacks entitlements necessary to submit to Apple macOS store ; MAUI WebView doesn't allow to web session to inspected in...
Read more >
service-names-port-numbers.txt
User Ports are assigned by IANA using the "IETF Review" process, the "IESG Approval" process, or the "Expert Review" process, as per [RFC6335]....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found