It is not possible to set the configuration of the WKWebView through the outlet of WKWebView form the storyboard because the configuration property of the WKWebView is read only, instead we need to programmatically configure as given below.
class ViewController: UIViewController, WKScriptMessageHandler {
@IBOutlet weak var webContentView: UIView!
var webView: WKWebView?
let contentController = WKUserContentController()
contentController.add(self, name: "callbackHandler")
let configuration = WKWebViewConfiguration()
configuration.userContentController = contentController
self.webView = WKWebView(frame: self.webContentView.bounds, configuration: configuration)
self.webContentView.addSubview(self.webView!)
}
And implement the WKScriptMessageHandler delegate method
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
if (message.name == "callbackHandler"){
print("\(message.body)")
}
}
Hope this helps...