From 71e54744ae5d52e99a5225bc054391f30a108f36 Mon Sep 17 00:00:00 2001 From: Toni Sevener Date: Wed, 10 Jul 2024 15:38:20 -0500 Subject: [PATCH] Add JS confirm support --- .../Code/SinglePageWebViewController.swift | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Wikipedia/Code/SinglePageWebViewController.swift b/Wikipedia/Code/SinglePageWebViewController.swift index 5571c397f5c..d7a8af6ba7a 100644 --- a/Wikipedia/Code/SinglePageWebViewController.swift +++ b/Wikipedia/Code/SinglePageWebViewController.swift @@ -61,6 +61,7 @@ class SinglePageWebViewController: ViewController { private lazy var webView: WKWebView = { let webView = WKWebView(frame: UIScreen.main.bounds, configuration: webViewConfiguration) webView.navigationDelegate = self + webView.uiDelegate = self return webView }() @@ -274,3 +275,20 @@ extension SinglePageWebViewController: WKNavigationDelegate { fakeProgressController.finish() } } + +extension SinglePageWebViewController: WKUIDelegate { + func webView(_ webView: WKWebView, runJavaScriptConfirmPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping (Bool) -> Void) { + + let alertController = UIAlertController(title: nil, message: message, preferredStyle: .alert) + let action1 = UIAlertAction(title: CommonStrings.okTitle, style: .default) { _ in + completionHandler(true) + } + let action2 = UIAlertAction(title: CommonStrings.cancelActionTitle, style: .default) { _ in + completionHandler(false) + } + alertController.addAction(action1) + alertController.addAction(action2) + + present(alertController, animated: true) + } +}