Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// delare WKScriptMessageHandler as delegate
// add to WKWebViewConfiguration init:
configuration.userContentController.addScriptMessageHandler(self, name: "log")
// MARK: WKScriptMessageHandler
func userContentController(userContentController: WKUserContentController, didReceiveScriptMessage message: WKScriptMessage) {
if (message.name == "log") {
print(message.body)
}
}
function logObject(obj) {
window.webkit.messageHandlers.log.postMessage(obj);
}
document.addEventListener('turbolinks:load', function() { logObject( window.location.toString() ) }, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment