flutter_inappwebview icon indicating copy to clipboard operation
flutter_inappwebview copied to clipboard

Many crashes on iOS: Completion handler was not called

Open frankteller-de opened this issue 2 years ago β€’ 6 comments

Technology Version
Flutter version 3.0.1
Plugin version 5.4.3+7
Android version -
iOS version 15.5, 15.4.1
Xcode version 13.4.1

Device information: any Apple devices

Description

Since about one week hundrets of iOS users get an app crash while open the webview. I can't reproduce the crash on my devices.

My code

InAppWebView(          
  key: Key(widget.url),
  gestureRecognizers: widget.enableScrolling ? (Set()..add(Factory<VerticalDragGestureRecognizer>(() => VerticalDragGestureRecognizer()))) : null,
  initialUrlRequest: URLRequest(
    url: Uri.parse(widget.url!),
    method: widget.method,
    headers: widget.headers,
    body: body        
  ), 
  initialOptions: InAppWebViewGroupOptions(              
    android: AndroidInAppWebViewOptions(
      useHybridComposition: true,
    ),
    crossPlatform: InAppWebViewOptions(
      verticalScrollBarEnabled: widget.enableScrolling,
      horizontalScrollBarEnabled: widget.enableScrolling,
      transparentBackground: true,
      useShouldOverrideUrlLoading: true,
      supportZoom: false
    )
  ),
  onProgressChanged: (InAppWebViewController controller, int progress) async {},
  onLoadHttpError: (InAppWebViewController controller, Uri? url, int statusCode, String description) {},
  onLoadError: (InAppWebViewController controller, Uri? url, int code, String message) {},
  onLoadStart: (InAppWebViewController controller, Uri? url) {},
  onOverScrolled: (InAppWebViewController controller, int x, int y, bool clampedX, bool clampedY) {},
  onScrollChanged: (InAppWebViewController controller, int x, int y) {},
  onLoadStop: (InAppWebViewController controller, Uri? url) async {},
  shouldInterceptAjaxRequest: (InAppWebViewController controller, AjaxRequest ajaxRequest) async {
    return ajaxRequest;
  },
  shouldOverrideUrlLoading: (InAppWebViewController controller, NavigationAction navigationAction) async {
    return NavigationActionPolicy.ALLOW;
  }
)

Stacktrace/Logcat

Fatal Exception: NSInternalInconsistencyException Completion handler passed to -[flutter_inappwebview.InAppWebView webView:decidePolicyForNavigationAction:preferences:decisionHandler:] was not called OR Completion handler passed to -[flutter_inappwebview.InAppWebView webView:didReceiveAuthenticationChallenge:completionHandler:] was not called

Fatal Exception: NSInternalInconsistencyException
0  CoreFoundation                 0x92d0c __exceptionPreprocess
1  libobjc.A.dylib                0x14ee4 objc_exception_throw
2  CoreFoundation                 0xe5ef8 __CFDictionaryCreateGeneric
3  WebKit                         0x18841c WebKit::CompletionHandlerCallChecker::~CompletionHandlerCallChecker()
4  WebKit                         0x278cc4 WTF::Ref<WebKit::CompletionHandlerCallChecker, WTF::RawPtrTraits<WebKit::CompletionHandlerCallChecker> >::~Ref()
5  WebKit                         0x35b500 WTF::BlockPtr<void (WKNavigationActionPolicy, WKWebpagePreferences*)> WTF::BlockPtr<void (WKNavigationActionPolicy, WKWebpagePreferences*)>::fromCallable<WebKit::NavigationState::NavigationClient::decidePolicyForNavigationAction(WebKit::WebPageProxy&, WTF::Ref<API::NavigationAction, WTF::RawPtrTraits<API::NavigationAction> >&&, WTF::Ref<WebKit::WebFramePolicyListenerProxy, WTF::RawPtrTraits<WebKit::WebFramePolicyListenerProxy> >&&, API::Object*)::$_14>(WebKit::NavigationState::NavigationClient::decidePolicyForNavigationAction(WebKit::WebPageProxy&, WTF::Ref<API::NavigationAction, WTF::RawPtrTraits<API::NavigationAction> >&&, WTF::Ref<WebKit::WebFramePolicyListenerProxy, WTF::RawPtrTraits<WebKit::WebFramePolicyListenerProxy> >&&, API::Object*)::$_14)::'lambda'(void const*)::__invoke(void const*)
6  libsystem_blocks.dylib         0x1840 _Block_release
7  flutter_inappwebview           0x52da0 (Missing UUID 3b8a5ec4e6f1389ab250ba26511a2d80)
8  libswiftCore.dylib             0x2efc20 _swift_release_dealloc
9  flutter_inappwebview           0x55e64 (Missing UUID 3b8a5ec4e6f1389ab250ba26511a2d80)
10 libswiftCore.dylib             0x2efc20 _swift_release_dealloc
11 flutter_inappwebview           0x532ec (Missing UUID 3b8a5ec4e6f1389ab250ba26511a2d80)
12 libswiftCore.dylib             0x2efc20 _swift_release_dealloc
13 libsystem_blocks.dylib         0x1840 _Block_release
14 libsystem_blocks.dylib         0x1840 _Block_release
15 libsystem_blocks.dylib         0x1840 _Block_release
16 Flutter                        0x3b408 (Missing UUID bab62788d88339b192aed18e13dece71)
17 Flutter                        0x3b3a8 (Missing UUID bab62788d88339b192aed18e13dece71)
18 Flutter                        0x4e51b8 (Missing UUID bab62788d88339b192aed18e13dece71)
19 Flutter                        0x4e49d8 (Missing UUID bab62788d88339b192aed18e13dece71)
20 Flutter                        0x4e47c8 (Missing UUID bab62788d88339b192aed18e13dece71)
21 Flutter                        0x54a380 (Missing UUID bab62788d88339b192aed18e13dece71)
22 Flutter                        0x555edc (Missing UUID bab62788d88339b192aed18e13dece71)
23 Flutter                        0x555910 (Missing UUID bab62788d88339b192aed18e13dece71)
24 Flutter                        0x3da718 (Missing UUID bab62788d88339b192aed18e13dece71)
25 Flutter                        0x3e8268 (Missing UUID bab62788d88339b192aed18e13dece71)
26 Flutter                        0x3e8a94 (Missing UUID bab62788d88339b192aed18e13dece71)
27 Flutter                        0x305064 (Missing UUID bab62788d88339b192aed18e13dece71)
28 Flutter                        0x308360 (Missing UUID bab62788d88339b192aed18e13dece71)
29 CoreFoundation                 0xa7258 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__
30 CoreFoundation                 0x30af8 __CFRunLoopDoTimer
31 CoreFoundation                 0x2b6b0 __CFRunLoopDoTimers
32 CoreFoundation                 0xb3a4 __CFRunLoopRun
33 CoreFoundation                 0x1e240 CFRunLoopRunSpecific
34 Flutter                        0x308230 (Missing UUID bab62788d88339b192aed18e13dece71)
35 Flutter                        0x307c14 (Missing UUID bab62788d88339b192aed18e13dece71)
36 libsystem_pthread.dylib        0x3348 _pthread_start
37 libsystem_pthread.dylib        0x1948 thread_start

frankteller-de avatar Jun 15 '22 06:06 frankteller-de

πŸ‘‹ @hankfrinkle

NOTE: This comment is auto-generated.

Are you sure you have already searched for the same problem?

Some people open new issues but they didn't search for something similar or for the same issue. Please, search for it using the GitHub issue search box or on the official inappwebview.dev website, or, also, using Google, StackOverflow, etc. before posting a new one. You may already find an answer to your problem!

If this is really a new issue, then thank you for raising it. I will investigate it and get back to you as soon as possible. Please, make sure you have given me as much context as possible! Also, if you didn't already, post a code example that can replicate this issue.

In the meantime, you can already search for some possible solutions online! Because this plugin uses native WebView, you can search online for the same issue adding android WebView [MY ERROR HERE] or ios WKWebView [MY ERROR HERE] keywords.

Following these steps can save you, me, and other people a lot of time, thanks!

github-actions[bot] avatar Jun 15 '22 06:06 github-actions[bot]

Yes. Same issue here. I've included our stacktrace as well. Our implementation of the InAppWebview is almost the same as provided above.

We are running on 5.4.3+7

Exception Type: EXC_CRASH (SIGABRT)
Crashed Thread: 6

Application Specific Information:
Completion handler passed to -[flutter_inappwebview.InAppWebView webView:decidePolicyForNavigationAction:preferences:decisionHandler:] was not called

Thread 6 Crashed:
0   CoreFoundation                  0x330235288         __exceptionPreprocess
1   libobjc.A.dylib                 0x361cac740         objc_exception_throw
2   CoreFoundation                  0x33028c38c         +[NSException raise:format:]
3   WebKit                          0x34dd02b64         WebKit::CompletionHandlerCallChecker::~CompletionHandlerCallChecker
4   WebKit                          0x34de0f3ac         WTF::Ref<T>::~Ref
5   WebKit                          0x34df0a3a4         WTF::BlockPtr<T>::fromCallable<T>::lambda::__invoke
6   libsystem_blocks.dylib          0x412493800         _Block_release
7   flutter_inappwebview            0x10559cc6c         InAppWebView.webView
8   libswiftCore.dylib              0x339aca420         _swift_release_dealloc
9   flutter_inappwebview            0x10559fe30         thunk for closure
10  libswiftCore.dylib              0x339aca420         _swift_release_dealloc
11  flutter_inappwebview            0x10559d1ac         InAppWebView.webView

luzannew avatar Aug 01 '22 12:08 luzannew

Same issue here. My app on ios received this error 144 times in half a month

phamconganh avatar Aug 04 '22 07:08 phamconganh

also having this issue with 5.4.3+7 on three separate devices running all on iOS 15.5.0.

implementation:

    InAppWebView(
      initialUrlRequest: URLRequest(url: Uri.parse(url), headers: headers),
      onWebViewCreated: (controller) {
        webViewController = controller;
      },
    )

so far not reproducible. Also using headers same as @codeforce-dev (1 Authorization header in my case). Any recommendations of handling this for now, e.g. with onLoadError?

a clone of this issue exists on https://github.com/pichillilorenzo/flutter_inappwebview/issues/1128

fix92 avatar Aug 17 '22 10:08 fix92

It could be that a missing decisionHandler at the end of the method is responsible for the crashes.

#L1568

frankteller-de avatar Aug 17 '22 14:08 frankteller-de

Same here. We went down from an almost crash-free app to a couple of hundreds of daily crashes. The dent on the below graph was the rollout of a new version, with the same Dart InAppWebView usage code base.

This version got updated from flutter 2 to flutter 3.0.5 and from InAppWebView 5.3.2 to 5.4.3, and we never had this issue while developing or on an extensive internal QA testing. But, after rolling out, we had more than 10% of our user base experiencing at least one crash.

image

Fatal Exception: NSInternalInconsistencyException
0  CoreFoundation                 0x99288 __exceptionPreprocess
1  libobjc.A.dylib                0x16744 objc_exception_throw
2  CoreFoundation                 0xf0390 __CFDictionaryCreateGeneric
3  WebKit                         0x1a8de8 WebKit::CompletionHandlerCallChecker::~CompletionHandlerCallChecker()
4  WebKit                         0x2833a0 WTF::Ref<WebKit::CompletionHandlerCallChecker, WTF::RawPtrTraits<WebKit::CompletionHandlerCallChecker> >::~Ref()
5  WebKit                         0x3b1ebc WTF::BlockPtr<void (WKNavigationActionPolicy, WKWebpagePreferences*)> WTF::BlockPtr<void (WKNavigationActionPolicy, WKWebpagePreferences*)>::fromCallable<WebKit::NavigationState::NavigationClient::decidePolicyForNavigationAction(WebKit::WebPageProxy&, WTF::Ref<API::NavigationAction, WTF::RawPtrTraits<API::NavigationAction> >&&, WTF::Ref<WebKit::WebFramePolicyListenerProxy, WTF::RawPtrTraits<WebKit::WebFramePolicyListenerProxy> >&&, API::Object*)::$_14>(WebKit::NavigationState::NavigationClient::decidePolicyForNavigationAction(WebKit::WebPageProxy&, WTF::Ref<API::NavigationAction, WTF::RawPtrTraits<API::NavigationAction> >&&, WTF::Ref<WebKit::WebFramePolicyListenerProxy, WTF::RawPtrTraits<WebKit::WebFramePolicyListenerProxy> >&&, API::Object*)::$_14)::'lambda'(void const*)::__invoke(void const*)
6  libsystem_blocks.dylib         0x1804 _Block_release
7  flutter_inappwebview           0x54bd4 (Missing UUID 8ef4032387a731b7a617a0bc5e3b5ecb)
8  libswiftCore.dylib             0x39c424 _swift_release_dealloc
9  flutter_inappwebview           0x57d9c (Missing UUID 8ef4032387a731b7a617a0bc5e3b5ecb)
10 libswiftCore.dylib             0x39c424 _swift_release_dealloc
11 flutter_inappwebview           0x55114 (Missing UUID 8ef4032387a731b7a617a0bc5e3b5ecb)
12 libswiftCore.dylib             0x39c424 _swift_release_dealloc
13 libsystem_blocks.dylib         0x1804 _Block_release
14 libsystem_blocks.dylib         0x1804 _Block_release
15 libsystem_blocks.dylib         0x1804 _Block_release
16 Flutter                        0x3bbf0 (Missing UUID b5f419596300357c85f161f5e6e0920d)
17 Flutter                        0x3bb90 (Missing UUID b5f419596300357c85f161f5e6e0920d)
18 Flutter                        0x4e5d6c (Missing UUID b5f419596300357c85f161f5e6e0920d)
19 Flutter                        0x4e558c (Missing UUID b5f419596300357c85f161f5e6e0920d)
20 Flutter                        0x4e537c (Missing UUID b5f419596300357c85f161f5e6e0920d)
21 Flutter                        0x54af24 (Missing UUID b5f419596300357c85f161f5e6e0920d)
22 Flutter                        0x5569f0 (Missing UUID b5f419596300357c85f161f5e6e0920d)
23 Flutter                        0x556424 (Missing UUID b5f419596300357c85f161f5e6e0920d)
24 Flutter                        0x3daf00 (Missing UUID b5f419596300357c85f161f5e6e0920d)
25 Flutter                        0x3e8a50 (Missing UUID b5f419596300357c85f161f5e6e0920d)
26 Flutter                        0x3e927c (Missing UUID b5f419596300357c85f161f5e6e0920d)
27 Flutter                        0x30584c (Missing UUID b5f419596300357c85f161f5e6e0920d)
28 Flutter                        0x308b48 (Missing UUID b5f419596300357c85f161f5e6e0920d)
29 CoreFoundation                 0xae678 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__
30 CoreFoundation                 0x32654 __CFRunLoopDoTimer
31 CoreFoundation                 0x2ce00 __CFRunLoopDoTimers
32 CoreFoundation                 0xb4b0 __CFRunLoopRun
33 CoreFoundation                 0x1ebc8 CFRunLoopRunSpecific
34 Flutter                        0x308a18 (Missing UUID b5f419596300357c85f161f5e6e0920d)
35 Flutter                        0x3083fc (Missing UUID b5f419596300357c85f161f5e6e0920d)
36 libsystem_pthread.dylib        0x19ac _pthread_start
37 libsystem_pthread.dylib        0xe68 thread_start

jenseralmeida avatar Sep 09 '22 20:09 jenseralmeida

Any temporary solution for this?

definitelyme avatar Sep 29 '22 16:09 definitelyme

Hi, I have some additional information to share.

I have reverted the InAppWebView back from version 5.4.3 to 5.3.2, and the issue with the [WebKit::CompletionHandlerCallChecker::~CompletionHandlerCallChecker()] is still happening. For context, this issue started after updating the app to use Flutter from v2 to v3, and the InAppWebView from 5.3.2 to 5.4.3. For the sake of testing, I have released a new version keeping Flutter v3, and downgrading the InAppWebView back to 5.3.2, and this did not fix the issue.

So, whenever it is happening, it is related to the Flutter v3 upgrade, and some sort of incompatibility with this library.

For additional context please look into my original comment at https://github.com/pichillilorenzo/flutter_inappwebview/issues/1221#issuecomment-1242406861

jenseralmeida avatar Oct 04 '22 23:10 jenseralmeida

same issue !!!

nne998 avatar Oct 08 '22 03:10 nne998

The "problematic" events seem to be:

I did some tests and checked again the native code but I can't find why it could happen. Native completions handlers should be called in every situation.

  • Have you tried to update the Flutter version?
  • Are you sure that your implementation of the events isn't causing the issue?

pichillilorenzo avatar Oct 13 '22 20:10 pichillilorenzo

The "problematic" events seem to be:

I did some tests and checked again the native code but I can't find why it could happen. Native completions handlers should be called in every situation.

  • Have you tried to update the Flutter version?
  • Are you sure that your implementation of the events isn't causing the issue?

Hi @pichillilorenzo, to summarize, it appears that updating from flutter v2 to v3 was the root cause of the issue. My application did not change besides the upgrade, and I had no crashes before (see the linked comments below for the immediate effect after deploying the Flutter v3 app).

You can see more details about this on https://github.com/pichillilorenzo/flutter_inappwebview/issues/1221#issuecomment-1242406861 and https://github.com/pichillilorenzo/flutter_inappwebview/issues/1221#issuecomment-1267714192

jenseralmeida avatar Oct 13 '22 23:10 jenseralmeida

@jenseralmeida which version of Flutter are you using right now? Have you tried to upgrade to the latest one?

pichillilorenzo avatar Oct 13 '22 23:10 pichillilorenzo

@jenseralmeida which version of Flutter are you using right now? Have you tried to upgrade to the latest one?

@pichillilorenzo , currently the application is running on flutter v3.0.5 and using the InAppWebView 5.3.2. Before, we were running the app on Flutter v2 + InAppWebView v5.3.2, and it was an almost crash-free application.

On the InAppWebView side, the first crashing version was using Flutter v3.0.5+InAppWebView 5.4.3, and that was the version that did start to crash. So, I have downgraded it to 5.3.2 hoping that it would fix the issue, as we were fine while using Flutter v2 + InAppWebView v5.3.2.

Right now, the only difference between the problematic version, and the previous almost crash-free version is the version of Flutter. I have not updated it to v3.3 yet, and now there is no plan for us to do that. I'd be glad to provide additional info once we move forward to upgrade Flutter.

One more thing to recall from my previous comments is that we had an extensive QA cycle, (plus the development testing by itself), and we never had the issue while testing or developing. This brings us to a very specific use case that is causing the problem, but we could not find it yet.

In the end, I can not downgrade the Flutter version, as somehow the Android Keyboard did stop to work for the pages rendered by the InAppWebView while using the Flutter v2.

jenseralmeida avatar Oct 14 '22 00:10 jenseralmeida

@jenseralmeida Ok, thanks for the info! I have released a new major version of the plugin right now (version 6.0.0-beta.1) that has a different implementation of flutter callbacks on the native side that might resolve the issue. Anyway, keep me updated πŸ‘

pichillilorenzo avatar Oct 14 '22 01:10 pichillilorenzo

It should be fixed now with release 5.5.0+4

pichillilorenzo avatar Oct 20 '22 08:10 pichillilorenzo

The new crashing report after upgrading to 5.5.0+4. Thanks to the team β‰ˆfor your awesome work. For context, check https://github.com/pichillilorenzo/flutter_inappwebview/issues/1221#issuecomment-1242406861

image

cc @pichillilorenzo

jenseralmeida avatar Nov 10 '22 19:11 jenseralmeida