Repository navigation
feat(core): list web view cookies and clear website data - #892
Conversation
21c4c4a to
90a4625
Compare
3e1dea6 to
9b96067
Compare
|
Review status: not merging yet. The code review is done and fixes are pushed, but the new macOS native test fails on CI every time, and the latest run looks like a real platform bug, not a flaky test. Pushed on top of the rebase onto main:
Checks that passed: TSX plugins cannot reach The blocker. On GitHub's
So on macOS 15 there are two possible causes:
|
Scope.WebCookies lists the cookies of the persistent store every web view of the app shares, HttpOnly ones and every field included, picked by a URL a request would send them to or by a domain and the hosts under it, and Scope.ClearWebsiteData removes the store's cookies, storage, service workers and caches; both work with no web view shown. They ride ItemWebCookies, whose request now carries an op. Apple lists with WKHTTPCookieStore getAllCookies and clears with removeDataOfTypes, Windows with the profile's GetCookies and ClearBrowsingDataAll through a page web view or the hidden one, restarting a request whose web view closes first, Linux with WebKitGTK's get_all_cookies and its website data manager, and Android with CookieManager.getCookie by URL alone, names and values, and removeAllCookies with WebStorage.deleteAllData. The web, tvOS, watchOS and mini programs answer unavailable. Linux now keeps a cookie SetWebCookies writes until the second its Expires names. The gallery's WebView demo sets, lists and clears cookies. Fixes #112.
ClearBrowsingDataAll deletes the profile's caches from disk, which can outlast the six seconds a cookie request waits before calling itself lost, so a clear that succeeded could answer an error. A clear now waits a minute. Access's and the TSX capabilities' comments now say listing and clearing the store are what no capability grants, with a test for the whole-store resource.
On the hosted macOS 15 runners WebKit ends the first run's process before it writes the cookie the page set last, so the second run listed none and failed. The second run now lists the example.test cookies SetWebCookies wrote before any web view shows, has the page set its cookie and storage again, lists the page's cookie and then clears, so what ClearWebsiteData must remove is there in that run.
WebKit before 313745@main (https://webkit.org/b/315310), macOS 15's among it, answers WKHTTPCookieStore getAllCookies: with no cookies while the data store's network process has not started, and nothing starts it before the app's first web view. So WebCookies before any web view showed listed none of the cookies an earlier run kept on disk. WebCookies now fetches the store's cookie records first, which starts the process on a persistent store. SetWebCookies and ClearWebsiteData needed nothing: setCookie: and removeDataOfTypes: start it themselves. The macOS test goes back to listing the first run's cookies, the page's and SetWebCookies', and clearing them in a second run with no web view, and logs what the store lists before anything else.
9b96067 to
bf3b04f
Compare
|
Reviewed. Root cause: WebKit before 313745@main (https://webkit.org/b/315310), including macOS 15's, answers |
Summary
Adds
Scope.WebCookiesandScope.ClearWebsiteData, the listing and clearing half of the web views' persistent cookie store thatSetWebCookies(#387) started.cx.WebCookies(core.WebCookieFilter{URL: …} | {Domain: …} | {}, done)lists the store's cookies, HttpOnly ones included, with everyWebCookiefield, whether or not a web view is mounted. AURLfilter picks what a request to that URL would send (RFC 6265 domain and path match, Secure only for https, expired dropped); aDomainfilter picks the domain and every host under it; the zero filter picks all. Results come sorted by host, path and name.cx.ClearWebsiteData(done)removes the store's cookies, local and session storage, IndexedDB, service workers and caches.ItemWebCookies/EventWebCookies:WebCookiesRequestgains anOp(set, list, clear) and aFilter, and a list answers its cookies in the event'sData, so the backends that answer "unavailable" (web, tvOS, watchOS, mini programs) need no change.Accessholds toAccessWebView+AccessCookiesfor the filter's URL,https://<domain>/, or""for the whole store and for clearing (no TSX capability grants it, as forSetWebCookies).nsgotestlists fromApp.WebCookies, empties it on clear and counts clears inApp.WebsiteDataClears.WebCookiesClearWebsiteDataWKHTTPCookieStore getAllCookies:, filtered in Go; Foundation has no SameSite None, which reads as the defaultremoveDataOfTypes:allWebsiteDataTypes modifiedSince:distantPastICoreWebView2CookieManager::GetCookies(""), filtered in GoICoreWebView2Profile2::ClearBrowsingDataAllviaICoreWebView2_13::get_Profilewebkit_cookie_manager_get_all_cookies(bound only where WebKitGTK ≥ 2.42 has it), filtered in Gowebkit_website_data_manager_clear(WEBKIT_WEBSITE_DATA_ALL, 0)CookieManager.getCookie(url): names and values only,Domain= the URL's host; aDomainor zero filter answersUnavailableremoveAllCookies+flush+WebStorage.deleteAllData(the HTTP cache stays)UnavailableUnavailableTwo fixes found on the way, both in unreleased #387 code:
SetWebCookiesturnedExpiresinto a max age counted from now, ending the cookie up to a second early; it now sets the exact expiry, so a cookie lists back as it was written.The gallery's WebView demo gets a Cookies card that sets an HttpOnly cookie for nsgo.dev, lists the site's cookies and clears the store.
Fixes #112
Targets
core,base,ui,tsx, thensgotool)Screenshots
The gallery's WebView demo on macOS (
-target macos, 1200×800), before and after "Set a cookie" was pressed:Verification
go tool nsgo check -target macos,windows,linux,android,web,ios,tvos,watchos(every target vetted)go tool nsgo test: full headless suite on Linux, 3006 passed; the only failures were two Android Java-fixture tests that needjavacon that host, unrelated. On macOS:core,internal/driver,nsgotest,internal/platform/apple,internal/platform/android,examples/gallery,tsx/pkg,internal/moduletest,cmd/nsgo/harmony.go tool nsgo test -target macos ./internal/platform/macos -run WebCookies: newTestWebCookiesListsAndClearWebsiteDataClears. A local server's page sets anHttpOnlycookie, writeslocalStorageand makes an IndexedDB database, next toSetWebCookiescookies for.example.test,www.example.testandother.test. After the web view unmounts, a URL filter lists the page's cookie and a domain filter lists the two example.test ones, with every field. After a restart with no web view mounted, the same lists come back; thenClearWebsiteDataleaves the store empty, and a page loaded afterwards sends noCookie, readslocalStorageas null and gets a freshly created database. A mutation that skips the clear makes the test fail.internal/platform/linux, WebKitGTK 2.52 under Xvfb).internal/platform/windows, WebView2, interactive session) passes, withTestSetWebCookiesReachesThePagesLoadedAfterandTestHoldsWebCookiesSkipsWhatTheStoreDrops.nsgotesttarget test set, listed by URL and domain, cleared and listed the store with no page. On Android the URL list came back as names/values only and the domain list asUnavailable, as documented.driver.FilterWebCookies(domain/path/Secure/expiry matching), core's filter validation, Access gating and clearing, Apple'sNSHTTPCookieround trip, and Android's message encoding and Cookie-header parsing, with a check that its op constants matchProtocol.java.Not verified: real HTTPS sign-ins on devices (tracked in the roadmap row), and a tvOS or web run of the unavailable path (covered only by the shared
driver.NoWebCookiesanswer and core's mapping).