MBS Plugin: failing to call WKPolicyForNavigationActionDecisionHandlerMBS.Allow crashes

@Christian_Schmitz

This code using WKWebViewControlMBS 25.2, tested in macOS 15.5 using Xojo 2025 R2…

Sub decidePolicyForNavigationAction(navigationAction as WKNavigationActionMBS, decisionHandler as WKPolicyForNavigationActionDecisionHandlerMBS) Handles decidePolicyForNavigationAction
  var url as string = navigationAction.request.URL
  if CancelLoad(url) then  // cancelLoad is an event on this subclass
    decisionHandler.Cancel
  else
    decisionHandler.Allow  // OOPS: I had forgot this line
  end if
End Sub

I had forgot to add the call to decisionHandler.Allow and without it the app was hard crashing with this stack trace:

StackTrace
Application Specific Backtrace 0:
0   CoreFoundation                      0x00007ff803510e52 __exceptionPreprocess + 242
1   libobjc.A.dylib                     0x00007ff802fde12d objc_exception_throw + 62
2   CoreFoundation                      0x00007ff803510cf0 +[NSException raise:format:] + 220
3   WebKit                              0x00007ff909b809eb _ZN6WebKit28CompletionHandlerCallCheckerD2Ev + 133
4   WebKit                              0x00007ff909be6623 _ZNK3WTF20ThreadSafeRefCountedIN6WebKit28CompletionHandlerCallCheckerELNS_17DestructionThreadE0EE5derefEv + 27
5   WebKit                              0x00007ff909d3450b _ZZN3WTF8BlockPtrIFv24WKNavigationActionPolicyEE12fromCallableIZN6WebKit15NavigationState16NavigationClient31decidePolicyForNavigationActionERNS5_12WebPageProxyEONS_3RefIN3API16NavigationActionENS_12RawPtrTraitsISC_EENS_21DefaultRefDerefTraitsISC_EEEEONSA_INS5_27WebFramePolicyListenerProxyENSD_ISJ_EENSF_ISJ_EEEEE3$_1EES3_T_ENUlPKvE_8__invokeESR_ + 83
6   libsystem_blocks.dylib              0x00007ff8030ab1cf _call_dispose_helpers_excp + 37
7   libsystem_blocks.dylib              0x00007ff8030ab004 _Block_release + 211
8   WebKit                              0x00007ff909d29ecb _ZN6WebKit15NavigationState16NavigationClient31decidePolicyForNavigationActionERNS_12WebPageProxyEON3WTF3RefIN3API16NavigationActionENS4_12RawPtrTraitsIS7_EENS4_21DefaultRefDerefTraitsIS7_EEEEONS5_INS_27WebFramePolicyListenerProxyENS8_ISE_EENSA_ISE_EEEE + 1333
9   WebKit                              0x00007ff90a06d1ff _ZN6WebKit12WebPageProxy31decidePolicyForNavigationActionEON3WTF3RefINS_15WebProcessProxyENS1_12RawPtrTraitsIS3_EENS1_21DefaultRefDerefTraitsIS3_EEEERNS_13WebFrameProxyEONS_20NavigationActionDataEONS1_17CompletionHandlerIFvONS_14PolicyDecisionEEEE + 8205
10  WebKit                              0x00007ff90a06b083 _ZN6WebKit12WebPageProxy42decidePolicyForNavigationActionAsyncSharedEON3WTF3RefINS_15WebProcessProxyENS1_12RawPtrTraitsIS3_EENS1_21DefaultRefDerefTraitsIS3_EEEEONS_20NavigationActionDataEONS1_17CompletionHandlerIFvONS_14PolicyDecisionEEEE + 357
11  WebKit                              0x00007ff90a06aeff _ZN6WebKit12WebPageProxy36decidePolicyForNavigationActionAsyncEONS_20NavigationActionDataEON3WTF17CompletionHandlerIFvONS_14PolicyDecisionEEEE + 35
12  WebKit                              0x00007ff909bfdef8 _ZN6WebKit12WebPageProxy17didReceiveMessageERN3IPC10ConnectionERNS1_7DecoderE + 15334
13  WebKit                              0x00007ff90a629690 _ZN3IPC18MessageReceiverMap15dispatchMessageERNS_10ConnectionERNS_7DecoderE + 216
14  WebKit                              0x00007ff90a0db641 _ZN6WebKit15WebProcessProxy15dispatchMessageERN3IPC10ConnectionERNS1_7DecoderE + 29
15  WebKit                              0x00007ff909c37ded _ZN6WebKit15WebProcessProxy17didReceiveMessageERN3IPC10ConnectionERNS1_7DecoderE + 1527
16  WebKit                              0x00007ff90a624c87 _ZN3IPC10Connection15dispatchMessageEN3WTF9UniqueRefINS_7DecoderEEE + 233
17  WebKit                              0x00007ff90a625052 _ZN3IPC10Connection24dispatchIncomingMessagesEv + 506
18  JavaScriptCore                      0x00007ff90181ab2b _ZN3WTF7RunLoop11performWorkEv + 507
19  JavaScriptCore                      0x00007ff90181b88a _ZN3WTF7RunLoop11performWorkEPv + 26
20  CoreFoundation                      0x00007ff8034a360e __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17

The fix is easy, just make sure you either call .Allow or .Deny in all cases.

But perhaps this mistake shouldn’t crash the app?

So if you don’t call Allow or Deny, WebKit raises an exception, which is not caught.

So basically you would need NSExceptionHandlerMBS class to catch this.

Good info - Perhaps you can add that to the MBS documentation as it’s somewhat of a subtle trap.

Or maybe MBS should just catch it and raise a Xojo exception to make it easier to diagnose?

I think I can change it to call something automatically if you don’t do that to avoid the crash.