From 225e916342da3f3439016710d74218380ccfeb86 Mon Sep 17 00:00:00 2001 From: Ibrahim Awwal Date: Tue, 30 Sep 2025 22:39:16 +0000 Subject: [PATCH] Delete cookies before syncing them from WebView to HTTPCookieStorage Otherwise, when cookies are deleted on the WebView side of things, they may never get deleted from HTTPCookieStorage, which can lead to unexpected behavior. --- Source/Turbo/Navigator/Navigator.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Source/Turbo/Navigator/Navigator.swift b/Source/Turbo/Navigator/Navigator.swift index 9c5b0655..0bd97138 100644 --- a/Source/Turbo/Navigator/Navigator.swift +++ b/Source/Turbo/Navigator/Navigator.swift @@ -229,6 +229,11 @@ extension Navigator: SessionDelegate { guard let url = session.activeVisitable?.initialVisitableURL else { return } Task { @MainActor in + // To ensure deletions in the WebView are mirrored, first remove any shared cookies + // for this URL, then set the cookies read from WKWebView. + let storage = HTTPCookieStorage.shared + (storage.cookies(for: url) ?? []).forEach { storage.deleteCookie($0) } + let cookies = await WKWebsiteDataStore.default().httpCookieStore.allCookies() HTTPCookieStorage.shared.setCookies(cookies, for: url, mainDocumentURL: url) delegate?.requestDidFinish(at: url)