uno: Mac Catalyst (arm64): WebView is blocking keyboard input

Current behavior

Add a UnoWKWebView, WebView or WKWebView to the UI (code-behind or in XAML does not matter)

The browser control accepts mouse inputs. The browser control does not accept keyboard inputs.

Also, global shortcuts like CMD-Q (quit app) do not work anymore, they seem to be blocked

I know that this worked in earlier v4.x versions of Uno

This happens for both maccatalyst-arm64 as well as maccatalyst-x64

Expected behavior

WebView should accept keyboard input, and not block global shortcuts

How to reproduce it (as minimally and precisely as possible)

See the attached repro, it is just an empty project with a mainpage, in whose constructor I placed this code:

var webView = new UnoWKWebView();
webView.LoadRequest(new Foundation.NSUrlRequest(new Foundation.NSUrl("https://github.com")));
Content = webView;

repro.zip

Workaround

I don’t know of any workarounds, any workaround (if possible) would be appreciated

Works on UWP/WinUI

Yes

Environment

Uno.WinUI / Uno.WinUI.WebAssembly / Uno.WinUI.Skia

NuGet package version(s)

Uno.WinUI, v4.5.9 Uno.WinUI, v4.6.0-dev.253

Affected platforms

macOS

IDE

Visual Studio for Mac

IDE version

No response

Relevant plugins

No response

Anything else we need to know?

No response

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 40 (26 by maintainers)

Most upvoted comments

Hi Uno folks, I work at Microsoft on .NET MAUI and Blazor Hybrid and we’re having what seems to be the exact same issue with WKWebView on MacCatalyst. I reproed the same issue using Xcode and Swift to build a MacCatalyst app, just to make sure it wasn’t an issue in the .NET layer (it wasn’t). I filed an Apple Feedback issue with a detailed bug report and repro steps.

You can see a bit more on this issue: https://github.com/dotnet/maui/issues/13934#issuecomment-1480380796

The Apple Feedback issue ID is FB12076485 (though I don’t think it’s publicly visible anywhere).

@Eilon have you ever heard back from Apple about this ? thanks!

I just checked the Apple Feedback Assistant item and unfortunately there are no updates on it.

@dr1rrb what kind (arch) of a Mac did you use when you tried to duplicate the issue ?

I was testing on an x64 (Intel core i7) Mac with Ventura 13.1

How Microsoft deals with Mac Catalyst is a bit weird. It’s a JITed application for x64 that requires the interpreter (or it crash) or an AOTed application for arm64 (or Apple rejects the app) without the interpreter (or it crash).

That means there’s a lot of differences between the binaries for both architectures. Starting with their sizes… 4.4 vs 207 MB for debug builds.

❯ l bin/Debug/net6.0-maccatalyst/maccatalyst-x64/sdk.app/Contents/MacOS/sdk
-rwxr-xr-x@ 1 poupou  staff   4.4M 30 Jan 13:08 bin/Debug/net6.0-maccatalyst/maccatalyst-x64/sdk.app/Contents/MacOS/sdk

❯ l bin/Debug/net6.0-maccatalyst/maccatalyst-arm64/sdk.app/Contents/MacOS/sdk
-rwxr-xr-x@ 1 poupou  staff   207M 30 Jan 13:20 bin/Debug/net6.0-maccatalyst/maccatalyst-arm64/sdk.app/Contents/MacOS/sdk

Something happens on arm64 that affects/breaks the keyboard input. It might be something inside Uno (since a simple test app with the MS SDK works) or something else that gets included (the linked output won’t be identical and, next step, needs to be analyzed).

The easy workaround (at least for now) would be to build/ship only the x64 version of the application and let Rosetta do it’s magic for arm64-based Macs.

This works fine on an Apple silicon (M2) Mac when Rosetta is used. IOW it’s related to the binary architecture (x64 works, arm64 does not), not the Uno code itself.

This is likely an Apple bug (looking thru them) and I’ll see if I can find a workaround.

@Eilon Any update on this issue or workaround? After almost a year since your last update, it seems pretty bewildering to me that apple would let such a fundamental issue exist for so long. Why would anyone even want to use a Catalyst app when it doesn’t provide the basic functionality of keyboard navigation?

@Eilon have you ever heard back from Apple about this ? thanks!

Swift app built for arm64 and running on arm64 -> works!

Screenshot 2023-03-23 at 5 01 46 PM

For some reason the app crash (very early at startup) when I build for x64

https://gist.github.com/spouliot/4ef368f9717f3d66adad96e59f436730

I got to go now - but I’ll look at why this crashed asap

<div> Gist</div><div>gist:4ef368f9717f3d66adad96e59f436730</div><div>GitHub Gist: instantly share code, notes, and snippets.</div>

I’m sure there’s something, somewhere and I likely have missed it - and will, shamefully bang my head on the wall several time once it’s found… At the same time I’m sure there’s something wrong on Apple side, but it’s unclear how we are, only sometimes, tripping over it.

And I 100% agree with this and will join you 😄

If possible, could you try running my Swift example on your Apple arm64 machine? This here: https://github.com/Eilon/MacCatalystWebViewKeyboard

It’s a default Swift app I made in Xcode, and then found some code that creates a webview, and then I had it load static HTML. That 100% non-Microsoft app (no .NET, no C#, no Xamarin/MAUI etc.) doesn’t work on my Intel x64 Venture machine on MacCatalyst. The exact same project works fine on iPadOS.

I wonder if that repros on your Apple Silicon on either MacCat or iPadOS?

<div> GitHub</div><div>GitHub - Eilon/MacCatalystWebViewKeyboard: MacCatalyst WKWebView keyboard problem repro</div><div>MacCatalyst WKWebView keyboard problem repro. Contribute to Eilon/MacCatalystWebViewKeyboard development by creating an account on GitHub.</div>

Using

            this.AddSubview(webView);

instead of

            Content = webView;

does not change the behaviour… which kind of exclude most of the Uno specific code.

That debugging issue was a red herring 😦

The debugging path changed (while trying workarounds) so the binaries were not identical. After rebuilding the new binaries they behave identically between the debugger and the command-line executions (but still different between x86 and arm64).

Now I have to re-compare the logs between the x86 and arm64 - but they should be identical, IOW I still expect to see a problem with UITextInput on arm64 only… 😦

and, as expected, both custom-linker-options.txt files are identical - except for the paths…

I’m diffing the bin logs… which gives a quite large output, stay tuned.

For reference, this is the closest reported issue I found https://developer.apple.com/forums/thread/721141 but the answer I got (from the OP) is diverging from this case (issues with x64, nor arm64).

<div>Mac Catalyst WKWebView keyDown nev… | Apple Developer Forums</div>

Do you folks have a good contact for asking why there’s such a big .app size difference between x64 and arm64?

You can ask the MS folks (either the iOS/Mac or Mono teams) on Discord (DotNetEvolution) but I can answer that too 😃

4.4 sound super small. Are you sure the app was self-contained?

This was the size of the executable binaries, not the full application bundles.

4.4 MB (for x64) is very small since it’s JITed (and interpreted). So the executable size is mostly the Mono runtime and a few bits of native code. This means the .dll contains both the IL and the metadata.

207 MB (for arm64) is huge but everything it fully AOTed (there won’t be any JITing or interpreting at runtime). The executable size contains all the code, there’s no IL (at least for release builds) inside the .dll, only the metadata.

As Ahead of Time (AOT) means compiling every at build time you end up with a much larger executable (even if the linker helps a lot) and much longer build times. However you (generally) have much better performance at runtime, in particular application startup times are much better.

As expected using a WKWebView, instead of the UnoWKWebView, has the same behaviour.

OTOH this seems to work fine when using directly the Microsoft SDK (net7.0-maccatalyst).