diff --git a/firefox-ios/Client/Frontend/Browser/BrowserPrompts.swift b/firefox-ios/Client/Frontend/Browser/BrowserPrompts.swift index b964db093bf5..5d729f3f3702 100644 --- a/firefox-ios/Client/Frontend/Browser/BrowserPrompts.swift +++ b/firefox-ios/Client/Frontend/Browser/BrowserPrompts.swift @@ -40,16 +40,13 @@ protocol JSAlertInfo { struct MessageAlert: JSAlertInfo { let message: String let frame: WKFrameInfo - let completionHandler: (() -> Void)? func alertController() -> JSPromptAlertController { let alertController = JSPromptAlertController( title: titleForJavaScriptPanelInitiatedByFrame(frame), message: message, preferredStyle: .alert) - alertController.addAction(UIAlertAction(title: .OKString, style: .default) { _ in - completionHandler?() - }) + alertController.addAction(UIAlertAction(title: .OKString, style: .default)) alertController.alertInfo = self return alertController } diff --git a/firefox-ios/Client/Frontend/Browser/BrowserViewController/Extensions/BrowserViewController+WebViewDelegates.swift b/firefox-ios/Client/Frontend/Browser/BrowserViewController/Extensions/BrowserViewController+WebViewDelegates.swift index eed2dc6f8ed6..b7a59bfd28a1 100644 --- a/firefox-ios/Client/Frontend/Browser/BrowserViewController/Extensions/BrowserViewController+WebViewDelegates.swift +++ b/firefox-ios/Client/Frontend/Browser/BrowserViewController/Extensions/BrowserViewController+WebViewDelegates.swift @@ -57,14 +57,14 @@ extension BrowserViewController: WKUIDelegate { initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping () -> Void ) { - let messageAlert = MessageAlert(message: message, frame: frame, completionHandler: { - completionHandler() - self.logger.log("Javascript message alert was completed.", level: .info, category: .webview) - }) + let messageAlert = MessageAlert(message: message, frame: frame) if shouldDisplayJSAlertForWebView(webView) { logger.log("Javascript message alert will be presented.", level: .info, category: .webview) - present(messageAlert.alertController(), animated: true) + present(messageAlert.alertController(), animated: true) { + completionHandler() + self.logger.log("Javascript message alert was completed.", level: .info, category: .webview) + } } else if let promptingTab = tabManager[webView] { logger.log("Javascript message alert is queued.", level: .info, category: .webview) @@ -964,7 +964,7 @@ private extension BrowserViewController { func shouldDisplayJSAlertForWebView(_ webView: WKWebView) -> Bool { // Only display a JS Alert if we are selected and there isn't anything being shown - return (tabManager.selectedTab == nil ? false : tabManager.selectedTab!.webView == webView) + return ((tabManager.selectedTab == nil ? false : tabManager.selectedTab!.webView == webView)) && (self.presentedViewController == nil) }