fix(mac): ignore cancelled webchat navigations

This commit is contained in:
Peter Steinberger
2025-12-12 19:20:47 +00:00
parent e2ad0ed9f7
commit 3f7fcad9ac

View File

@@ -388,11 +388,19 @@ final class WebChatWindowController: NSWindowController, WKNavigationDelegate, N
}
func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {
if Self.shouldIgnoreNavigationError(error) {
webChatLogger.debug("webchat navigation cancelled (provisional)")
return
}
webChatLogger.error("webchat navigation failed (provisional): \(error.localizedDescription, privacy: .public)")
self.showError(error.localizedDescription)
}
func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
if Self.shouldIgnoreNavigationError(error) {
webChatLogger.debug("webchat navigation cancelled")
return
}
webChatLogger.error("webchat navigation failed: \(error.localizedDescription, privacy: .public)")
self.showError(error.localizedDescription)
}
@@ -483,6 +491,11 @@ final class WebChatWindowController: NSWindowController, WKNavigationDelegate, N
if let url = Bundle.module.url(forResource: "WebChat", withExtension: nil) { return url }
throw NSError(domain: "WebChat", code: 10, userInfo: [NSLocalizedDescriptionKey: "WebChat assets missing"])
}
private static func shouldIgnoreNavigationError(_ error: Error) -> Bool {
let ns = error as NSError
return ns.domain == NSURLErrorDomain && ns.code == NSURLErrorCancelled
}
}
extension WebChatWindowController {