diff --git a/ios/Capacitor/Capacitor/WebViewDelegationHandler.swift b/ios/Capacitor/Capacitor/WebViewDelegationHandler.swift index 56c2137f54..a06a23953a 100644 --- a/ios/Capacitor/Capacitor/WebViewDelegationHandler.swift +++ b/ios/Capacitor/Capacitor/WebViewDelegationHandler.swift @@ -169,10 +169,15 @@ internal class WebViewDelegationHandler: NSObject, WKNavigationDelegate, WKUIDel // MARK: - WKUIDelegate public func webView(_ webView: WKWebView, runJavaScriptAlertPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping () -> Void) { - guard let viewController = bridge?.viewController else { + guard var viewController = bridge?.viewController else { + completionHandler() return } + if let presentedVC = viewController.presentedViewController, !presentedVC.isBeingDismissed { + viewController = presentedVC + } + let alertController = UIAlertController(title: nil, message: message, preferredStyle: .alert) alertController.addAction(UIAlertAction(title: "Ok", style: .default, handler: { (_) in