         webViewTopConstraint.constant = 0
         focusNavigationView.isHidden = true
         navigationController?.setNavigationBarHidden(false, animated: false)
+    }
+    
+    private func removeScriptMessageHandlers() {
+        
+        guard let userContentController = webView?.configuration.userContentController,
+            !scriptMessageHandlers.isEmpty else {
+                return
+        }
+        
+        for handler in scriptMessageHandlers {
+            userContentController.removeScriptMessageHandler(forName: handler.name)
+        }
+        
+        scriptMessageHandlers.removeAll()
+    }
+    
+    private func addScriptMessageHandlers(to contentController: WKUserContentController) {
+        
+        guard !scriptMessageHandlers.isEmpty else {
+            return
+        }
+        
+        for handler in scriptMessageHandlers {
+            contentController.add(handler.handler, name: handler.name)
+        }
     }
     
     private func configureWebView() {

        super.viewWillDisappear(animated)
    }
    
    @objc func keyboardDidHide() {
        inputViewsController.resetFormattingAndStyleSubmenus()
    }

        }
        
        contentController.addUserScript(setupUserScript)
        
        scriptMessageHandlers.append(ScriptMessageHandler(handler: setupUserScript, name: setupUserScript.messageHandlerName))

        scriptMessageHandlers.append(ScriptMessageHandler(handler: messagingController, name: SectionEditorWebViewMessagingController.Message.Name.codeMirrorMessage))
        
        scriptMessageHandlers.append(ScriptMessageHandler(handler: messagingController, name: SectionEditorWebViewMessagingController.Message.Name.codeMirrorSearchMessage))
        
        scriptMessageHandlers.append(ScriptMessageHandler(handler: messagingController, name: SectionEditorWebViewMessagingController.Message.Name.smoothScrollToYOffsetMessage))
        
        scriptMessageHandlers.append(ScriptMessageHandler(handler: messagingController, name: SectionEditorWebViewMessagingController.Message.Name.replaceAllCountMessage))

        scriptMessageHandlers.append(ScriptMessageHandler(handler: messagingController, name: SectionEditorWebViewMessagingController.Message.Name.didSetWikitextMessage))
        
        addScriptMessageHandlers(to: contentController)
        
        configuration.userContentController = contentController
        webView = SectionEditorWebView(frame: .zero, configuration: configuration)
