Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is WKErrorWebViewInvalidated?

I have a WKWebView to which I send javascript via -[WKWebView evaluateJavaScript:completionHandler:] Periodically, the web view returns the following error:

Error Domain=WKErrorDomain Code=3 "The WKWebView was invalidated" UserInfo={NSLocalizedDescription=The WKWebView was invalidated

The corresponding WKError seems to be WKErrorWebViewInvalidated, but the WKError.h only seems to say the following about this error:

@constant WKErrorWebViewInvalidated                Indicates that the WKWebView was invalidated.

Once I receive this error from the web view I can no longer execute any subsequent javascript and I need to throw the web view away and create a new one. I've searched online for more details on this error, but have not been able to find anything of substance. Can someone help explain what this error means and how I can debug what might be causing it. Thanks.

like image 493
Daniel Shteremberg Avatar asked Jan 20 '16 01:01

Daniel Shteremberg


1 Answers

I had this error with a web view that was detached from the view hierarchy. Make sure your WKWebView has a superview and a window while you run the script if you see this error.

like image 100
user2378197 Avatar answered Oct 20 '22 01:10

user2378197