UIWebview gets stuck with the following message in console

前端 未结 4 1137
醉梦人生
醉梦人生 2020-12-29 08:38

UIWebview gets stuck with the following message in console.

void SendDelegateMessage(NSInvocation*): delegate (webView:didFinishLoadForFrame:)   
failed to         


        
4条回答
  •  盖世英雄少女心
    2020-12-29 08:58

    FWIW, it looks like my particular timeout was occurring due to a javascript error in rare scenarios. You might try wrapping your JS in a try/catch or improving it to be more error-tolerant.


    More details: I was using the following JS string:

    NSString* js = @"document.getElementById(\"main\").offsetHeight";
    int height = [[_web_view stringByEvaluatingJavaScriptFromString:js] intValue];
    

    I knew that this UIWebView problem could happen if the web view was not fully loaded (eg. JS called before the webViewDidFinishLoad: method, so I guessed that perhaps the "main" object was missing. Thus, I modified my JS to the following and it worked:

    NSString* js = @"document.getElementById(\"main\") ? document.getElementById(\"main\").offsetHeight : -1";
    

提交回复
热议问题