fix(ios): retain WKHTTPCookieStore observer so cookie sync works#8520
Open
Cybertron01Z wants to merge 1 commit into
Open
fix(ios): retain WKHTTPCookieStore observer so cookie sync works#8520Cybertron01Z wants to merge 1 commit into
Cybertron01Z wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
CAPBridgeViewController.webViewConfiguration(for:)added aCapacitorWKCookieObserverto the web view'shttpCookieStorebut did not keep any reference to it:Per Apple's docs,
WKHTTPCookieStoredoes not retain its observers:So the observer was deallocated immediately after
add(_:)returned, andcookiesDidChange(in:)never fired. The result: cookies set inside theWKWebViewwere never synced back toHTTPCookieStorage.This PR holds a strong reference to the observer on the view controller, and also retains the store it was added to so the observer can be removed in
deinit, as the docs require.Change Type
Rationale / Problems Fixed
The cookie observer was dead on arrival —
cookiesDidChangenever ran because the instance had no owner and was released right away. WKWebView →HTTPCookieStoragecookie syncing has therefore been silently broken.The observer is now stored in an optional property assigned at the call site, so a subclass that overrides
webViewConfiguration(for:)without calling the observer code creates no dangling instance. A weak reference to the exactWKHTTPCookieStoreis kept sodeinitcan remove the observer per Apple's contract.Tests or Reproductions
Tested manually:
Screenshots / Media
N/A
Platforms Affected
Notes / Comments
The default
websiteDataStoreis the.default()singleton, so the store reference stays valid for the controller's lifetime; the weak reference avoids extending the store's lifetime or creating a retain cycle.