You should add the following in the view controllers deinit deinit { webView.configuration.userContentController.removeScriptMessageHandlerForName("buttonClicked") webView.configuration.userContentController.removeAllUserScripts() }