             selectionGestureRecognizer?.isEnabled = false
             selectionGestureRecognizer?.isEnabled = true
         }
+        selectionGestureRecognizer = nil
 
         var linkURL: URL?
         if let urlString = data["link"] as? String {

        if !showCustomContextMenu {
            return
        }

        let data = message.body as! [String: AnyObject]

        // On sites where <a> elements have child text elements, the text selection delegate can be triggered

        return true
    }

    // Hack to detect the built-in context menu gesture recognizer.
    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldBeRequiredToFailBy otherGestureRecognizer: UIGestureRecognizer) -> Bool {
        // On iOS 11 the gestureRecognizer has been renamed. Check for both names.
        let gestureNames = ["_UIKeyboardBasedNonEditableTextSelectionGestureCluster", "_UIKeyboardBasedNonEditableTextSelectionGestureController"]
        if let otherDelegate = otherGestureRecognizer.delegate, gestureNames.reduce(false, { $0 || String(describing: otherDelegate).contains($1) }) {
            selectionGestureRecognizer = otherGestureRecognizer
        }
        return otherGestureRecognizer.delegate?.description.contains("WKContentView") ?? false
    }

    func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
        // If the selection gesture is nil we are likely not trying to select text in the webview.
        return selectionGestureRecognizer == nil && showCustomContextMenu
    }
}
