Skip to content

WebView error if we leave page while it's navigating #20627

@ESO-ST

Description

@ESO-ST

Description

If we have a webview and it's navigating somewhere, say for example we pressed on a link and it's loading a page, if while that navigation is taking place we leave the page where the webview is, we get an error.

ObjCRuntime.ObjCException
  Message=Objective-C exception thrown.  Name: NSInternalInconsistencyException Reason: Completion handler passed to -[Microsoft_Maui_Platform_MauiWebViewUIDelegate webView:contextMenuConfigurationForElement:completionHandler:] was not called
Native stack trace:
	0   CoreFoundation                      0x00007ff80048d28d __exceptionPreprocess + 242
	1   libobjc.A.dylib                     0x00007ff800057894 objc_exception_throw + 48
	2   CoreFoundation                      0x00007ff80048d16b -[NSException initWithCoder:] + 0
	3   WebKit                              0x00000001119ba879 _ZN6WebKit28CompletionHandlerCallCheckerD2Ev + 127
	4   WebKit                              0x0000000111a223d5 _ZNK3WTF20ThreadSafeRefCountedIN6WebKit28CompletionHandlerCallCheckerELNS_17DestructionThreadE0EE5derefEv + 33
	5   WebKit                              0x00000001121a0a69 _ZZN3WTF8BlockPtrIFvP26UIContextMenuConfigurationEE12fromCallableIZ70-[WKContentView(WKInteractionPreview) continueContextMenuInteraction:]E5$_102EES4_T_ENUlPKvE_8__invokeES9_ + 31
	6   libsystem_blocks.dylib              0x00007ff8000c1214 _call_dispose_helpers_excp + 45
	7   libsystem_blocks.dylib              0x00007ff8000c1ea5 _Block_release + 232
	8   libdispatch.dylib                   0x00007ff80014bd3a _dispatch_client_callout + 8
	9   libdispatch.dylib                   0x00007ff80015aac0 _dispatch_main_queue_drain + 1420
	10  libdispatch.dylib                   0x00007ff80015a526 _dispatch_main_queue_callback_4CF + 31
	11  CoreFoundation                      0x00007ff8003e9850 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
	12  CoreFoundation                      0x00007ff8003e418b __CFRunLoopRun + 2463
	13  CoreFoundation                      0x00007ff8003e3409 CFRunLoopRunSpecific + 557
	14  GraphicsServices                    0x00007ff80a650187 GSEventRunModal + 137
	15  UIKitCore                           0x000000011b1df3a2 -[UIApplication _run] + 972
	16  UIKitCore                           0x000000011b1e3e10 UIApplicationMain + 123
	17  libxamarin-dotnet-debug.dylib       0x00000001056f850a xamarin_UIApplicationMain + 58
	18  libmonosgen-2.0.dylib               0x0000000105e960f5 do_icall + 341
	19  libmonosgen-2.0.dylib               0x0000000105e94887 do_icall_wrapper + 295
	20  libmonosgen-2.0.dylib               0x0000000105e855a6 mono_interp_exec_method + 3990
	21  libmonosgen-2.0.dylib               0x0000000105e82d13 interp_runtime_invoke + 259
	22  libmonosgen-2.0.dylib               0x0000000105f69748 mono_runtime_invoke_checked + 136
	23  libmonosgen-2.0.dylib               0x0000000105f7109b mono_runtime_exec_main_checked + 107
	24  libmonosgen-2.0.dylib               0x0000000105dd5482 mono_jit_exec + 354
	25  libxamarin-dotnet-debug.dylib       0x000000010573cbea xamarin_main + 1898
	26  WebViewCrashMidLoad                 0x0000000103dd4a04 main + 68
	27  dyld                                0x00000001047023ee start_sim + 10
	28  ???                                 0x00000001089f13a6 0x0 + 4439610278
  Source=Microsoft.iOS
  StackTrace:
   at ObjCRuntime.Runtime.ThrowNSException(IntPtr ns_exception) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/Runtime.cs:line 507
   at ObjCRuntime.Runtime.throw_ns_exception(IntPtr exc) in /Users/builder/azdo/_work/1/s/xamarin-macios/runtime/Delegates.generated.cs:line 279
   at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 58
   at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 94
   at WebViewCrashMidLoad.Program.Main(String[] args) in C:\Users\ortiz\source\repos\WebViewCrashMidLoad\WebViewCrashMidLoad\Platforms\iOS\Program.cs:line 13

Steps to Reproduce

press click me to open a modal page with a web view.
press on a link in the webview to make it load that url, while that's taking place leave the page by pressing click me.

Link to public reproduction project repository

https://github.com/ESO-ST/WebViewCrashMidLoad

Version with bug

8.0.7 SR2

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iOS 15

Did you find any workaround?

No response

Relevant log output

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-controls-webviewWebViewfixed-in-8.0.20fixed-in-8.0.40fixed-in-9.0.0-preview.4.10690i/regressionThis issue described a confirmed regression on a currently supported versionmigration-compatibilityXamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convertpartner/cat 😻this is an issue that impacts one of our partners or a customer our advisory team is engaged withplatform/ioss/triagedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions