-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebView on iOS using Navigating event fails with obj exception #11544
Comments
Hi @jjxtra. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time. |
If it helps, this seams to only happen when building to an iOS device from a Windows machine remotely. Running VS mac, I don't have the issue. |
I'm hitting this exact error but I don't have an exact repro yet. In my case I'm deriving from .NET MAUI's WebView in a custom control. I'm overriding a few things here and there but not very much. When I load some custom content into the WebView then on iOS specifically I get that same error after doing some navigations (and then the app crashes and quits). I'll try to debug more and see what a fix might be. |
This is because MauiWebViewUIDelegate.SetContextMenuConfiguration may not call completionHandler when no webView.Interactions is available. For workaround you should install WKView.UIDelegate where you going to call completion handler. Something like that: sealed class MauiWebViewUIDelegate2 : MauiWebViewUIDelegate
{
public MauiWebViewUIDelegate2(IWebViewHandler handler) : base(handler)
{
}
[SupportedOSPlatform("maccatalyst13.1")]
[SupportedOSPlatform("ios13.0")]
[UnsupportedOSPlatform("macos")]
[UnsupportedOSPlatform("tvos")]
public override void SetContextMenuConfiguration(WKWebView webView, WKContextMenuElementInfo elementInfo, Action<UIContextMenuConfiguration> completionHandler)
{
bool completionHandlerIsInvoked = false;
base.SetContextMenuConfiguration(webView, elementInfo, cfg =>
{
completionHandlerIsInvoked = true;
completionHandler(cfg);
});
if (completionHandlerIsInvoked == false)
completionHandler(null!);
}
}
sealed class WebViewHandler2 : WebViewHandler
{
WKUIDelegate? _delegate;
public static void MapWKUIDelegate2(IWebViewHandler handler, IWebView webView)
{
if (handler is WebViewHandler2 platformHandler)
handler.PlatformView.UIDelegate = platformHandler._delegate ??= new MauiWebViewUIDelegate2(handler);
}
}
// at your application startup
WebViewHandler.Mapper.Add(nameof(WKUIDelegate), WebViewHandler2.MapWKUIDelegate2);
// when maui app is created
app.ConfigureMauiHandlers(h => h.AddHandler<WebView, WebViewHandler2>()); |
Thanks for the workaround. Obviously it would be ideal not to have to do this kind of hackery. Can someone from Microsoft comment if this is reproduced on your end and if so is there a fix planned for .NET 8, or a patch for .NET 7? |
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process. |
We've probably just hit this issue in our app as well causing seemingly random crashes for some of our users. Unfortunately we can't pinpoint what is causing this exactly, but given the exception we're seeing, the workaround described above and the current implementation here it makes sense. According to the docs it seems you are supposed to call the completionHandler with |
I have unfortunately hit this issue as well. Similar set up and have tried the workaround suggested above however am finding it results in a hang/freeze when trying to return from the browser if external or the default email app for mailto links. Launching and returning from a https:// url works fine if I use the workaround and set the launch mode to: await Browser.Default.OpenAsync(uri, BrowserLaunchMode.SystemPreferred); |
We're also struggling with this issue, and decided we can't update our app because of it for the time being. Hopefully someone at Microsoft will respond and is willing to take the proposed PR by @jmezach soon! |
We're seeing the same issue on iOS, but when selecting links by pressing and holding. The link text is selected, but after a second the app crashes without displaying any context menu with this exact exception. Selecting normal text is fine and Android works fine. Edit: |
Verified this issue with Visual Studio 17.6.5(build 417). Can repro on iOS platform. |
I can confirm this also is an issue in .NET 8.100 final release. |
Hi, is it possible for you to upload a full project showcasing where this needs to be implemented? I'm new to .NET MAUI so could use all the help I can get! Thanks. |
Sorry this is late but just incase anyone else needs it: Firstly add that code to a class possibly down the ios platform directory as it's ios specific. In mauiprogram.cs add to your CreateMauiApp(); on the var builder add this .ConfigureMauiHandlers
Then add to App.cs or wherever you're mapping handlers
public App underneath InitializeComponent();
That will map the handler to the object so on iOS it has said extension. |
Description
I have an anchor tag which when clicked, is supposed to call the navigating event, where I inspect the url and do different things and set cancel to true.
Completion handler passed to -[Microsoft_Maui_Platform_MauiWebViewUIDelegate webView:contextMenuConfigurationForElement:completionHandler:] was not called.
Steps to Reproduce
Navigating="WebBrowser_Navigating"
Version with bug
7.0 (current)
Last version that worked well
Unknown/Other
Affected platforms
iOS
Affected platform versions
iOS 13, 14, 15, 16
Did you find any workaround?
No
Relevant log output
Works fine on Windows and Android, no issue.
The text was updated successfully, but these errors were encountered: