spx-ian-huynh opened a new issue, #1638:
URL: https://github.com/apache/cordova-ios/issues/1638

   ## Bug Report
   
   ### Problem
   
   The fix for #1605 (PR #1606, commit a706334) introduced a new crash by 
calling `[urlSchemeTask didFinish]` inside `webView:stopURLSchemeTask:`. Per 
Apple's WKURLSchemeTask documentation, calling any methods on a scheme task 
after `webView:stopURLSchemeTask:` is invoked throws an 
`NSInternalInconsistencyException`  "This task has already been stopped". 
[[LINK](https://developer.apple.com/documentation/webkit/wkurlschemetask/didfinish())]
   
   ### What is expected to happen?
   
   When WebKit calls `webView:stopURLSchemeTask:`, CDVURLSchemeHandler should 
clean up its internal state without calling any methods on the `urlSchemeTask` 
object.
   
   ### What does actually happen?
   
   The app crashes with:
   -[CDVURLSchemeHandler webView:stopURLSchemeTask:]
   NSInternalInconsistencyException - This task has already been stopped
   
   ### Root Cause
   
   In the current `CDVURLSchemeHandler.m` (after PR #1606), 
`stopURLSchemeTask:` calls `[urlSchemeTask didFinish]` for tasks owned by 
CDVURLSchemeHandler:
   
   ```
   - (void)webView:(WKWebView *)webView 
stopURLSchemeTask:(id<WKURLSchemeTask>)urlSchemeTask
   {
       CDVPlugin *plugin;
       @synchronized(self.handlerMap) {
           plugin = [self.handlerMap objectForKey:urlSchemeTask];
       }
   
       @synchronized(self.handlerMap) {
           [self.handlerMap removeObjectForKey:urlSchemeTask];
       }
   
       if ([plugin isEqual:[NSNull null]]) {
           [urlSchemeTask didFinish]; 
       } else if ([plugin respondsToSelector:@selector(stopSchemeTask:)]) {
           [plugin stopSchemeTask:urlSchemeTask];
       }
   }
   ```
   
   ### Potential fix
   It seems like there is a [fix 
](https://github.com/ionic-team/capacitor/pull/7482/files)for a very similar 
issue in capacitor.
   A potential safeguard could be to wrap task method calls with try/catch.
   
   
   ### Environment, Platform, Device
   cordova-ios: master branch commit a706334
   cordova: 13.0.0
   iOS: 17+
   Device: iPhone (physical devices and simulators)
   Rolled back to cordova-ios 7.1.1 as a workaround
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to