\Forcing a WKWebsiteDataStore proxy change onto existing connections without losing session state

Context: This is for a privacy relay in a browser, where the proxy is toggled on/off and rotated mid-session, so we can't lose the user's logged-in sessions when it engages.

  1. Connection pool behavior — is this expected? When we mutate proxyConfigurations on a live data store, the proxy only applies to newly-visited origins. Origins that already have established connections keep going direct — reloading the page, and even tearing down and recreating the WKWebView, doesn't move them onto the proxy. The only thing that reliably forces all traffic through the proxy is swapping in a brand-new WKWebsiteDataStore. Is that the intended behavior — i.e. is recreating the store the expected way to re-establish the connection pool — or is there a supported way to invalidate the existing connections so a mutated proxy config takes effect on already-loaded origins?

  2. What does fetchData/restoreData actually carry? To preserve the session across that store swap, we serialize the old store with fetchData(of: WKWebsiteDataStore.allWebsiteDataTypes()) and rehydrate the new one with restoreData(_:) (iOS 26). Passing the full allWebsiteDataTypes() set, does this round-trip everything those types represent — cookies, localStorage, IndexedDB, service worker registrations, etc. — into a store created with init(forIdentifier:)? And does anything not enumerated by allWebsiteDataTypes() — per-site permissions, tracking-prevention/ITP state — get dropped silently?

Answered by DTS Engineer in 890573022

Hi carson4444,

Thanks for asking! We'll answer your questions in your other thread.

Richard Yeh

 Developer Technical Support

Hi carson4444,

Thanks for asking! We'll answer your questions in your other thread.

Richard Yeh

 Developer Technical Support

This is a duplicate of https://developer.apple.com/forums/thread/830125. Please ignore in favor of https://developer.apple.com/forums/thread/830125

\Forcing a WKWebsiteDataStore proxy change onto existing connections without losing session state
 
 
Q