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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With