Reputation: 214
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.
Upvotes: 7
Views: 3489
Reputation: 880
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.
Upvotes: 4
Reputation: 34945
It means that the web content process has died. This is the process that runs the JavaScript and does the Networking part of the WKWebView
.
Unfortunately this process is managed by WebKit and you have zero control over it. So if your device runs low on memory, there is a very good change that it will randomly kill a web content process. That is when you receive the WKErrorWebViewInvalidated
error.
Upvotes: 0