I have observed similar behavior in my application running socket.io in a headless WKWebView. In my case, the web socket will disconnect all the time and not reconnect.
It seems that since WKWebView starts javascript off-process, it pauses any javascript that is considered inactive to save resources (<-IMO). Idle includes lack of parent or application / device inactive. So yes, it seems you are right that in most cases this requires a parent view. I was able to get around this using the following code:
WKWebViewConfiguration* webViewConfig =
This approach at least ensures javascript execution while the application is active and does not affect the user interface. If you need to display it later, you can remove the webView from keyWindow after rendering and resetting the frame. And, yes, I also noticed that this is not a problem in the simulator (javascript ALWAYS works, regardless of the state of the parent or application)
Hope this helps!
mattr source share