Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.

Commit 577ecd3

Browse files
authored
Fix crash on sites that open about:blank and so WKNavigation object is nil (#3961)
Task/Issue URL: https://app.asana.com/0/414709148257752/1209372383528747 **Description**: Do not crash on about:blank when site is redirected.
1 parent 5c05dbd commit 577ecd3

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

DuckDuckGo/SpecialErrorPage/SpecialErrorPageInterfaces/WebViewNavigationHandling.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ protocol WebViewNavigationHandling: AnyObject {
6969
/// - navigation: The navigation object for the operation.
7070
/// - error: The error that occurred.
7171
@MainActor
72-
func handleWebView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WebViewNavigation, withError error: NSError)
72+
func handleWebView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WebViewNavigation?, withError error: NSError)
7373

7474
/// Handles the successful completion of a navigation in the web view.
7575
///
7676
/// - Parameters:
7777
/// - webView: The web view that loaded the content.
7878
/// - navigation: The navigation object that finished.
7979
@MainActor
80-
func handleWebView(_ webView: WKWebView, didFinish navigation: WebViewNavigation)
80+
func handleWebView(_ webView: WKWebView, didFinish navigation: WebViewNavigation?)
8181
}

DuckDuckGo/SpecialErrorPage/SpecialErrorPageNavigationHandler.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ extension SpecialErrorPageNavigationHandler: WebViewNavigationHandling {
110110
}
111111

112112
@MainActor
113-
func handleWebView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WebViewNavigation, withError error: NSError) {
113+
func handleWebView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WebViewNavigation?, withError error: NSError) {
114114
guard let sslSpecialError = sslErrorPageNavigationHandler.makeNewRequestURLAndSpecialErrorDataIfEnabled(error: error) else { return }
115115
failedURL = sslSpecialError.error.url
116116
sslErrorPageNavigationHandler.errorPageVisited(errorType: sslSpecialError.type)
@@ -119,7 +119,7 @@ extension SpecialErrorPageNavigationHandler: WebViewNavigationHandling {
119119
}
120120

121121
@MainActor
122-
func handleWebView(_ webView: WKWebView, didFinish navigation: WebViewNavigation) {
122+
func handleWebView(_ webView: WKWebView, didFinish navigation: WebViewNavigation?) {
123123
isSpecialErrorPageRequest = false
124124
userScript?.isEnabled = webView.url == failedURL
125125
if webView.url != failedURL {

DuckDuckGoTests/MockTabDelegate.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,10 @@ class DummySpecialErrorPageNavigationHandler: SpecialErrorPageManaging {
178178

179179
}
180180

181-
func handleWebView(_ webView: WKWebView, didFailProvisionalNavigation navigation: any DuckDuckGo.WebViewNavigation, withError error: NSError) {}
182-
183-
func handleWebView(_ webView: WKWebView, didFinish navigation: any DuckDuckGo.WebViewNavigation) {}
181+
func handleWebView(_ webView: WKWebView, didFailProvisionalNavigation navigation: (any WebViewNavigation)?, withError error: NSError) {}
184182

183+
func handleWebView(_ webView: WKWebView, didFinish navigation: (any WebViewNavigation)?) {}
184+
185185
var errorData: SpecialErrorPages.SpecialErrorData?
186186

187187
func leaveSiteAction() {}

0 commit comments

Comments
 (0)