Skip to content

Commit

Permalink
Bail out early when navigation fails because of cancelled load
Browse files Browse the repository at this point in the history
  • Loading branch information
dus7 committed Nov 8, 2024
1 parent f743a06 commit 774d834
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion DuckDuckGo/TabViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1611,6 +1611,7 @@ extension TabViewController: WKNavigationDelegate {
}

func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
Logger.general.debug("didFailNavigation; error: \(error)")
adClickAttributionDetection.onDidFailNavigation()
hideProgressIndicator()
webpageDidFailToLoad()
Expand All @@ -1632,6 +1633,7 @@ extension TabViewController: WKNavigationDelegate {
}

func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {
Logger.general.debug("didFailProvisionalNavigation; error: \(error)")
adClickAttributionDetection.onDidFailNavigation()
hideProgressIndicator()
linkProtection.setMainFrameUrl(nil)
Expand All @@ -1644,7 +1646,7 @@ extension TabViewController: WKNavigationDelegate {
if error.code == 102 && error.domain == "WebKitErrorDomain" {
return
}

if let url = url,
let domain = url.host,
error.code == Constants.frameLoadInterruptedErrorCode {
Expand All @@ -1655,6 +1657,15 @@ extension TabViewController: WKNavigationDelegate {
self.url = webView.url
}

// Bail out before showing error when navigation was cancelled by the user
if error.code == NSURLErrorCancelled && error.domain == NSURLErrorDomain {
webpageDidFailToLoad()

// Reset url to current one, as navigation was not successful
self.url = webView.url
return
}

// wait before showing errors in case they recover automatically
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
self.showErrorNow()
Expand Down

0 comments on commit 774d834

Please sign in to comment.