From 35f06895cee428831882154447d35db5e0948556 Mon Sep 17 00:00:00 2001 From: Kyle Hickinson Date: Thu, 7 Nov 2024 12:31:45 -0500 Subject: [PATCH] [iOS] Fix crash if internal pages are stopped prior to fully loading --- .../Interstitial Pages/InternalSchemeHandler.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ios/brave-ios/Sources/Brave/Frontend/Browser/Interstitial Pages/InternalSchemeHandler.swift b/ios/brave-ios/Sources/Brave/Frontend/Browser/Interstitial Pages/InternalSchemeHandler.swift index a82847880a94..b17b378b591a 100644 --- a/ios/brave-ios/Sources/Brave/Frontend/Browser/Interstitial Pages/InternalSchemeHandler.swift +++ b/ios/brave-ios/Sources/Brave/Frontend/Browser/Interstitial Pages/InternalSchemeHandler.swift @@ -127,6 +127,11 @@ public class InternalSchemeHandler: NSObject, WKURLSchemeHandler { let path = url.path.starts(with: "/") ? String(url.path.dropFirst()) : url.path + if activeTasks.object(forKey: urlSchemeTask) != nil { + // Already a task ongoing, technically this shouldn't happen. + return + } + let task = Task { // For non-main doc URL, try load it as a resource if !urlSchemeTask.request.isPrivileged, @@ -168,5 +173,7 @@ public class InternalSchemeHandler: NSObject, WKURLSchemeHandler { activeTasks.setObject(TaskHolder(task: task), forKey: urlSchemeTask) } - public func webView(_ webView: WKWebView, stop urlSchemeTask: WKURLSchemeTask) {} + public func webView(_ webView: WKWebView, stop urlSchemeTask: WKURLSchemeTask) { + activeTasks.removeObject(forKey: urlSchemeTask) + } }