         }
         
         contentController.addUserScript(setupUserScript)
-        contentController.add(setupUserScript, name: setupUserScript.messageHandlerName)
-        
-        contentController.add(messagingController, name: SectionEditorWebViewMessagingController.Message.Name.codeMirrorMessage)
-        contentController.add(messagingController, name: SectionEditorWebViewMessagingController.Message.Name.codeMirrorSearchMessage)
-
-        contentController.add(messagingController, name: SectionEditorWebViewMessagingController.Message.Name.smoothScrollToYOffsetMessage)
-        contentController.add(messagingController, name: SectionEditorWebViewMessagingController.Message.Name.replaceAllCountMessage)
-        
-        contentController.add(messagingController, name: SectionEditorWebViewMessagingController.Message.Name.didSetWikitextMessage)
+        
+        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)

            setWikitextToWebViewIfReady()
        }
    }
    
    private let findAndReplaceHeaderTitle = WMFLocalizedString("find-replace-header", value: "Find and replace", comment: "Find and replace header title.")
    

        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() {
