Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I get crash in iOS11 ..... #302

Closed
huanghualove opened this issue Sep 13, 2017 · 41 comments
Closed

I get crash in iOS11 ..... #302

huanghualove opened this issue Sep 13, 2017 · 41 comments

Comments

@huanghualove
Copy link

'Completion handler passed to -[WKWebViewJavascriptBridge webView:decidePolicyForNavigationAction:decisionHandler:] was not called'

reason: 'Completion handler passed to -[WKWebViewJavascriptBridge webView:decidePolicyForNavigationAction:decisionHandler:] was called more than once'

How to resolve this problem ?? thank you .

WVJB Bug Report

Thanks for reporting an issue with WebViewJavascriptBridge.

Do these 4 things and I will fix your problem!

  1. Go to https://github.com/marcuswestin/WebViewJavascriptBridge and click Fork.
  2. Clone your fork, cd into it and run make test. All tests should pass!
  3. Edit Tests/WebViewJavascriptBridgeTests/BridgeTests.m and create a new, failing test which demostrates your issue.
  4. Create a pull request for https://github.com/marcuswestin/WebViewJavascriptBridge

That's it!

I will take it from there and promise that I'll fix your problem ASAP.

If you don't do this then I can't help you!

And I probably won't :)

Cheers,
@marcuswestin

@madordie
Copy link

madordie commented Sep 14, 2017

@marcuswestin

This is a must-have crash


info:

#0 Thread
NSInternalInconsistencyException
Completion handler passed to -[WKWebViewJavascriptBridge webView:decidePolicyForNavigationAction:decisionHandler:] was called more than once

and stack info

CoreFoundation	0x0000000186187d38 0x0000000186046000 + 1318200
1 libobjc.A.dylib	0x000000018569c528 objc_exception_throw + 56
2 CoreFoundation	0x0000000186187c80 0x0000000186046000 + 1318016
3 WebKit	0x00000001951acbdc 0x000000019517b000 + 203740
4 WebKit	0x00000001951f1700 0x000000019517b000 + 485120
5 xxxx_ent	0x0000000101472840 _T0SC24WKNavigationActionPolicyOIyBy_ABIxy_TR + 40
6 xxxx_ent	0x00000001014726cc _T014xxxx_ent24XXXBaseWebViewControllerC03webE0ySo05WKWebE0C_So18WKNavigationActionC15decidePolicyForySC0ijL0Oc15decisionHandlertF + 2860
7 xxxx_ent	0x00000001014edd18 _T014xxxx_ent20XXXWebViewControllerC03webD0ySo05WKWebD0C_So18WKNavigationActionC15decidePolicyForySC0hiK0Oc15decisionHandlertF + 1776
8 xxxx_ent	0x0000000101500108 _T014xxxx_ent20XXXWebViewControllerC03webD0ySo05WKWebD0C_So18WKNavigationActionC15decidePolicyForySC0hiK0Oc15decisionHandlertFTo + 180
9 WebViewJavascriptBridge	0x000000010546b6b0 -[WKWebViewJavascriptBridge webView:decidePolicyForNavigationAction:decisionHandler:] + 712
10 WebKit	0x00000001951ef254 0x000000019517b000 + 475732
11 WebKit	0x00000001953571b4 0x000000019517b000 + 1950132
12 WebKit	0x000000019537eac8 0x000000019517b000 + 2112200
13 WebKit	0x0000000195377bf4 0x000000019517b000 + 2083828
14 WebKit	0x00000001951ecba8 0x000000019517b000 + 465832
15 WebKit	0x00000001953c98b4 0x000000019517b000 + 2418868
16 WebKit	0x00000001951af8b0 0x000000019517b000 + 215216
17 WebKit	0x00000001951ad0d4 0x000000019517b000 + 205012
18 WebKit	0x00000001951afae0 0x000000019517b000 + 215776
19 JavaScriptCore	0x000000018d3b4d10 0x000000018ca87000 + 9624848
20 JavaScriptCore	0x000000018d3b4fd0 0x000000018ca87000 + 9625552
21 CoreFoundation	0x0000000186130358 0x0000000186046000 + 959320
22 CoreFoundation	0x00000001861302d8 0x0000000186046000 + 959192
23 CoreFoundation	0x000000018612fb60 0x0000000186046000 + 957280
24 CoreFoundation	0x000000018612d738 0x0000000186046000 + 948024
25 CoreFoundation	0x000000018604e2d8 CFRunLoopRunSpecific + 436
26 GraphicsServices	0x0000000187edff84 GSEventRunModal + 100
27 UIKit	0x000000018f5fa880 UIApplicationMain + 208
28 xxxx_ent	0x0000000101000c40 main + 444
29 libdyld.dylib	0x0000000185b7256c 0x0000000185b71000 + 5484

@wealon
Copy link

wealon commented Sep 15, 2017

i have the same bug

1 similar comment
@ranshon
Copy link

ranshon commented Sep 18, 2017

i have the same bug

@huanghualove
Copy link
Author

So how do we solve this problem?

@ranshon
Copy link

ranshon commented Sep 18, 2017

this bug occur in XCode9 iOS11.

@huanghualove
Copy link
Author

maybe you can add this:

if ([_base isWebViewJavascriptBridgeURL:url]) {
if ([_base isBridgeLoadedURL:url]) {
[_base injectJavascriptFile];
} else if ([_base isQueueMessageURL:url]) {
[self WKFlushMessageQueue];
} else {
[_base logUnkownMessage:url];
}
decisionHandler(WKNavigationActionPolicyCancel);
return; // add This-------
}

@madordie
Copy link

in my project.

if WebViewJavascriptBridgeBase().isWebViewJavascriptBridgeURL(url) {
    return
}
decisionHandler(.allow)

Can be resolved by the above code. But do not know will not cause other effects.

可以看这里

@InfAspire
Copy link

Also - please note that the current testPerformanceExample test fails when you run make test with XCode 9 installed.

Test Case '-[WebViewJavascriptBridgeTests.BridgeTests testPerformanceExample]' started.
WebViewJavascriptBridge-master/WebViewJavascriptBridge/WKWebViewJavascriptBridge.m:155: error: -[WebViewJavascriptBridgeTests.BridgeTests testPerformanceExample] : failed: caught "NSInternalInconsistencyException", "Completion handler passed to -[WKWebViewJavascriptBridge webView:decidePolicyForNavigationAction:decisionHandler:] was called more than once"
...
Test Case '-[WebViewJavascriptBridgeTests.BridgeTests testPerformanceExample]' failed (0.849 seconds).

@longshao521
Copy link

I have the same bug.

@yinanwang1
Copy link

I have the same bug. I found this bug in the iOS 11 beta one month ago. I thought this crash must be resoled in the iOS 11. But it did not. So Apps will crash if the user upgrade their iPhone.

@AdamYLK
Copy link

AdamYLK commented Sep 20, 2017

i have the same bug but see something beside, when run in xcode8 and ios11 the crash didn't happened.
the bug in xcode9 with ios11,i think it may crashed by xcode9

@fifyrio
Copy link

fifyrio commented Sep 20, 2017

I have the same bug.

@zeroskylian
Copy link

set WKWebview navigationDelegate

@coderWeil
Copy link

I have the same bug ,thank for @huanghualove ,I had got it

@NXZXing
Copy link

NXZXing commented Sep 20, 2017

I have the same bug.

@HelloYJP
Copy link

thank for @huanghualove, it help me !

@cythb
Copy link

cythb commented Sep 20, 2017

a0cfcf6 With reference to this, I hope to be of help to you.

@plainfire
Copy link

i have the same bug

@Beyond-Chao
Copy link

- (void)webView:(WKWebView*)webView decidePolicyForNavigationAction:(WKNavigationAction*)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {

       WebViewJavascriptBridgeBase *base = [[WebViewJavascriptBridgeBase alloc] init];
        if ([base isWebViewJavascriptBridgeURL:navigationAction.request.URL]) {
            return;
        }  // Add this IF statement in my project,  don`t need modify WebViewJavascriptBridge`s source code.
        decisionHandler(WKNavigationActionPolicyAllow);
}

That`s solve my problem

@NXZXing
Copy link

NXZXing commented Sep 22, 2017 via email

@zsading
Copy link

zsading commented Sep 22, 2017

I have the same bug

@benleiken
Copy link

can we get a fix for this? @marcuswestin

@XGPASS
Copy link

XGPASS commented Sep 25, 2017

In WKWebViewJavascriptBridge ,I modify

- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
    if (webView != _webView) { return; }
    NSURL *url = navigationAction.request.URL;
    __strong typeof(_webViewDelegate) strongDelegate = _webViewDelegate;

    if ([_base isWebViewJavascriptBridgeURL:url]) {
        if ([_base isBridgeLoadedURL:url]) {
            [_base injectJavascriptFile];
        } else if ([_base isQueueMessageURL:url]) {
            [self WKFlushMessageQueue];
        } else {
            [_base logUnkownMessage:url];
        }
        decisionHandler(WKNavigationActionPolicyCancel);
        
    } else {
        if (strongDelegate && [strongDelegate respondsToSelector:@selector(webView:decidePolicyForNavigationAction:decisionHandler:)]) {
            [_webViewDelegate webView:webView decidePolicyForNavigationAction:navigationAction decisionHandler:decisionHandler];
        } else {
            decisionHandler(WKNavigationActionPolicyAllow);
        }
    }
}

@wangjunling888
Copy link

@huanghualove, @XGPASS, @NXZXing 你们的解决方案只能解决崩溃的bug, 但是js交互事件都没有了(Your solution can only solve the crash of the bug, but js interactive events are gone!!!)

@XGPASS
Copy link

XGPASS commented Sep 25, 2017

@wangjunling888 js交互事件依然可以使用;
(The js interaction event still exists)
develop2

@wangjunling888
Copy link

@XGPASS 我这边还是不行, 你可以吧你的demo发给我一份吗? 非常感谢!!!

@wangjunling888
Copy link

@XGPASS 我的邮箱 987424476@qq.com

@softwarefaith
Copy link

@wangjunling888 I test these code, but donot have the problem that you described.

@XGPASS
Copy link

XGPASS commented Sep 25, 2017

@wangjunling888 https://github.com/XGPASS/XGDevelopDemo
This is my test demo;
After pod install,Please modify the code :
In WKWebViewJavascriptBridge ,I modify

- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
    if (webView != _webView) { return; }
    NSURL *url = navigationAction.request.URL;
    __strong typeof(_webViewDelegate) strongDelegate = _webViewDelegate;

    if ([_base isWebViewJavascriptBridgeURL:url]) {
        if ([_base isBridgeLoadedURL:url]) {
            [_base injectJavascriptFile];
        } else if ([_base isQueueMessageURL:url]) {
            [self WKFlushMessageQueue];
        } else {
            [_base logUnkownMessage:url];
        }
        decisionHandler(WKNavigationActionPolicyCancel);
        
    } else {
        if (strongDelegate && [strongDelegate respondsToSelector:@selector(webView:decidePolicyForNavigationAction:decisionHandler:)]) {
            [_webViewDelegate webView:webView decidePolicyForNavigationAction:navigationAction decisionHandler:decisionHandler];
        } else {
            decisionHandler(WKNavigationActionPolicyAllow);
        }
    }
}

or modify

- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
    if (webView != _webView) { return; }
    NSURL *url = navigationAction.request.URL;
    __strong typeof(_webViewDelegate) strongDelegate = _webViewDelegate;

    if ([_base isWebViewJavascriptBridgeURL:url]) {
        if ([_base isBridgeLoadedURL:url]) {
            [_base injectJavascriptFile];
        } else if ([_base isQueueMessageURL:url]) {
            [self WKFlushMessageQueue];
        } else {
            [_base logUnkownMessage:url];
        }
        decisionHandler(WKNavigationActionPolicyCancel);
        return;
    }
    
    if (strongDelegate && [strongDelegate respondsToSelector:@selector(webView:decidePolicyForNavigationAction:decisionHandler:)]) {
        [_webViewDelegate webView:webView decidePolicyForNavigationAction:navigationAction decisionHandler:decisionHandler];
    } else {
        decisionHandler(WKNavigationActionPolicyAllow);
    }
}

我猜测主要原因是 Xcode9上,decisionHandler() 这个block回调,不允许多次被调用;
(I guess the main reason is that Xcode9, the decisionHandler block callback, does not allow multiple calls)

@wangjunling888
Copy link

@XGPASS 收到, 非常感谢, 我测试一下吧, 我的修改之后还是不行, 只是不崩溃了, 但是所有的交互事件都没有了, 我在找找原因吧!

@shenjialin
Copy link

if (webView != _webView) { return; }
NSURL *url = navigationAction.request.URL;
__strong typeof(_webViewDelegate) strongDelegate = _webViewDelegate;

WKNavigationActionPolicy policy=WKNavigationActionPolicyCancel;
if ([_base isWebViewJavascriptBridgeURL:url]) {
    if ([_base isBridgeLoadedURL:url]) {
        [_base injectJavascriptFile];
    } else if ([_base isQueueMessageURL:url]) {
        [self WKFlushMessageQueue];
    } else {
        [_base logUnkownMessage:url];
    }
}

if (strongDelegate && [strongDelegate respondsToSelector:@selector(webView:decidePolicyForNavigationAction:decisionHandler:)]) {
    [_webViewDelegate webView:webView decidePolicyForNavigationAction:navigationAction decisionHandler:decisionHandler];
} else {
    policy=WKNavigationActionPolicyAllow;
}
decisionHandler(policy);

@shenjialin
Copy link

shenjialin commented Sep 25, 2017

decisionHandler这个方法调用了两次导致崩溃,下面是我修改的代码,测试可用

if (webView != _webView) { return; }
NSURL *url = navigationAction.request.URL;
__strong typeof(_webViewDelegate) strongDelegate = _webViewDelegate;

WKNavigationActionPolicy policy=WKNavigationActionPolicyCancel;
if ([_base isWebViewJavascriptBridgeURL:url]) {
    if ([_base isBridgeLoadedURL:url]) {
        [_base injectJavascriptFile];
    } else if ([_base isQueueMessageURL:url]) {
        [self WKFlushMessageQueue];
    } else {
        [_base logUnkownMessage:url];
    }
}

if (strongDelegate && [strongDelegate respondsToSelector:@selector(webView:decidePolicyForNavigationAction:decisionHandler:)]) {
    [_webViewDelegate webView:webView decidePolicyForNavigationAction:navigationAction decisionHandler:decisionHandler];
} else {
    policy=WKNavigationActionPolicyAllow;
}
decisionHandler(policy);

@xiweiLee
Copy link

中国的小朋友看这里,我用了@huanghualove的办法是可以的,而且交互都还在,没毛病,可以解决问题的,我这个情况是用xcode9跑的程序加载wkwebview会出现崩溃,打印台提示'Completion handler passed to -[WKWebViewJavascriptBridge webView:decidePolicyForNavigationAction:decisionHandler:] was not called',不仅是在iOS 11上崩溃,而且在iOS 10上也崩溃,可以断定是xcode 9导致的问题,大家快去修改吧,不过上面有人说这么做会导致交互没有了,各位你们试试吧,有什么好的方法也发上去

@troypayne
Copy link

Nothing's working for me on my end. I hope an official patch is coming soon.

@alex-chan
Copy link

I have the same bug.

@wangjunling888
Copy link

上面的朋友@XGPASS 提供的方案是可行的, 之前我测试的js交互事件不可使用,是因为我们的前端工程师的失误造成的, 所以遇到相同问题的朋友可以暂时先采用@XGPASS提供的方案

@ouyrp
Copy link

ouyrp commented Sep 28, 2017

what is the _webViewDelegate

@shaveKevin
Copy link

hope to fix

@originme
Copy link
Contributor

originme commented Oct 9, 2017

See pull request, adding return will work for me.

wenxp pushed a commit to wenxp/WebViewJavascriptBridge that referenced this issue Oct 12, 2017
@yhl714387953
Copy link

I have the same bug.

@marcuswestin
Copy link
Owner

Fixed in #296.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.