iOS app: the page's confirm() is asked, not answered Cancel (#453)

WebViewController is the web view's WKUIDelegate but had no confirm
panel, so WebKit answered every confirm() false at once and showed
nothing: the page's nine confirm() calls, deleting a file and sharing a
Patreon address among them, could never go ahead in the app. It now
shows an alert with Cancel and OK. With another alert already up it
answers Cancel, as before, since one cannot be presented over the other.
The page has no alert() or prompt(), so those panels are left out.

Not compiled here: the Swift builds only on a Mac with Xcode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-14 04:08:43 +00:00
parent 0222c0b69a
commit 614f270a90
2 changed files with 18 additions and 0 deletions

View File

@@ -122,6 +122,20 @@ final class WebViewController: UIViewController, WKNavigationDelegate, WKUIDeleg
decisionHandler(.cancel)
}
/// The page's confirm(): without this WebKit answers Cancel at once and shows nothing, so
/// anything that asked first (deleting a file, sharing a Patreon address) could not go ahead
/// in the app (#453). The page uses no alert() or prompt().
func webView(_ webView: WKWebView, runJavaScriptConfirmPanelWithMessage message: String,
initiatedByFrame frame: WKFrameInfo,
completionHandler: @escaping @MainActor (Bool) -> Void) {
// Another alert already up cannot have this one over it: answered as before, Cancel.
guard presentedViewController == nil else { return completionHandler(false) }
let alert = UIAlertController(title: nil, message: message, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel) { _ in completionHandler(false) })
alert.addAction(UIAlertAction(title: "OK", style: .default) { _ in completionHandler(true) })
present(alert, animated: true)
}
func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!,
withError error: Error) {
let host = Server.url?.host ?? "the server"