Delete cookies before syncing them from WebView to HTTPCookieStorage #182
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR deletes cookies before syncing them from the WebView session 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.
I ran into an issue with our app where we were using URLSession.shared to make a request to log in to the app, and then copying cookies from HTTPCookieStorage to the WebView. On log out, we delete cookies relevant to the previously logged in user, and this does delete them from the WebView. But when we log back in to a different user account, the cookies from the previous user get restored. I looked around and it seems like deleted cookies in the WebView never get deleted from HTTPCookieStorage, though I don't know for sure if my understanding is correct. But I was able to solve it in my app by deleting all cookies on logout. But I think it makes most sense to fix it here, upstream, so that this issue doesn't bite other people. It seems like the logically correct thing to do to ensure that cookies are always in sync with what the WebView session has.