I\'m experimenting with WkWebKit talking back and forth between app and page. I can get javaScript to execute fine using WkWebView evaluateJavascript method, but when I try
I ran into this SO because I was experiencing the same issue and this is how I solved it using a custom CustomContentController (subclass of WKUserContentController) instance.
let userContentController = CustomContentController()
let webViewConfiguration = WKWebViewConfiguration()
webViewConfiguration.userContentController = userContentController
webView = WKWebView(frame: .zero, configuration: webViewConfiguration)
In my case the CustomContentController is a subclass of WKUserContentController in which the add(_ scriptMessageHandler: WKScriptMessageHandler, name: String) method is called, but I don't believe that is significant.
I believe that the WKUserContentController must be instantiated and applied to a WKWebViewConfiguration before the WKWebView is initialized via WKWebView(frame: .zero, configuration: webViewConfiguration)
If the WKWebView has been created and then you try change the WKWebViewConfiguration you will encounter window.webkit not being available in the JSContext.