WebView on iOS using Navigating event fails with obj exception
- Dominant language
- C#
- Stars
- 23.3k
- Forks
- 2k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 290
Description
### 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.`
```cs
private void WebBrowser_Navigating(object? sender, WebNavigatingEventArgs e)
{
e.Cancel = true;
// business logic here, snipped for brevity
}
```
### Steps to Reproduce
1. Create new maui app
2. Add webview component with an html anchor tag in the xaml that points to any url
3. Hook into the navigating event - `Navigating="WebBrowser_Navigating"`
4. Create callback in the xaml.cs file and in the navigating event callback, set e.Cancel to true
5. Deploy to iOS device
6. Click the anchor tag in the web view
7. Crash
### 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
```shell
Completion handler passed to -[Microsoft_Maui_Platform_MauiWebViewUIDelegate webView:contextMenuConfigurationForElement:completionHandler:] was not called.
```
Works fine on Windows and Android, no issue.
Contributor guide
Research direction
Start with the reported XAML WebView, the WebBrowser_Navigating callback, and the seven reproduction steps on an iOS device. Trace the iOS WebView behavior associated with the logged context-menu completion handler, then verify that cancelling an anchor navigation no longer crashes while Windows and Android behavior remains unaffected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, ios
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100