From 4928d7daa62819b14c4f0350764d53cb32aec4dc Mon Sep 17 00:00:00 2001 From: brave-builds <45370463+brave-builds@users.noreply.github.com> Date: Fri, 8 Nov 2024 05:01:41 +0100 Subject: [PATCH] [iOS] Fix crash if internal pages are stopped prior to fully loading (uplift to 1.74.x) (#26439) Uplift of #26434 (squashed) to beta --- .../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) + } }