Repository navigation
Description
Context
NSGo's web views keep a persistent website data store that every web view in the app shares. The app has no way to read that store or clear it.
- On Linux, one WebKitGTK network session serves every web view of an app ("one set of cookies and storage",
internal/platform/linux/web.go:304-306). NSGo fetches its cookie manager only to switch it to persistent SQLite storage (internal/platform/linux/web.go:320-322). The bindings stop atwebkit_network_session_get_cookie_managerandwebkit_cookie_manager_set_persistent_storage(internal/platform/linux/web.go:27-28,95-96). - On Apple, each
WKWebViewis built from a plainWKWebViewConfiguration(internal/platform/apple/web.go:249-256), so it usesWKWebsiteDataStore.defaultDataStore. Nothing reaches itshttpCookieStoreor callsremoveDataOfTypes:. - On Windows, every web view shares one WebView2 profile folder (
internal/platform/windows/web.go:120,124-131). NSGo never queriesICoreWebView2CookieManageror the profile'sClearBrowsingData. RefoffersReload,GoBack,GoForward,StopLoading,PostMessage,InjectJavaScript,SendInputandEvaluate(core/webview.go:216-279), and the driver's commands are the same set (internal/driver/webview.go:142-154). None of them reads cookies or stored data.
The only workaround today is Ref.Evaluate("document.cookie", …) (core/webview.go:279), and it falls short in three ways. It can't see HttpOnly cookies, which are the session cookies a sign-in sets. It doesn't return domain, path, expiry or the secure flag. And it only works while a page from that site is loaded.
#33 doesn't cover this. Its "request headers and cookies a load carries" row (from docs/roadmap.md:27) is about what the app adds to a request. Incognito (Draft PR #76) keeps one view's data in memory. Neither one lets an app read what the persistent store holds, or clear it.
Why it matters for real apps
Kando is a video player with a built-in browser. A user signs in to a video site in the app's web view and then saves a video from that site. yt-dlp does the download. It needs the site's cookies in Netscape format, HttpOnly session cookies included, or members-only and age-gated videos fail. On MyGo, Kando lists the store for the video's registrable domain (mygo.Cookies.List(mygo.CookieFilter{Domain: …})). It does this from the download pipeline, so the browser may already be on a different page (state_browse.go:94-106, 419-442). Kando also has a "Clear sign-in data…" command that empties the store through mygo.App.ClearBrowsingData (state_browse.go:99).
On NSGo, neither works on any of the three desktops. The only fallback is yt-dlp's --cookies-from-browser, which reads another browser's cookies, not the sign-in the user just completed in the app. On macOS it also needs Full Disk Access to read Safari's cookies. Other apps hit the same wall: any app that signs in through a web view and then calls the same site from Go (an API client, a sync engine, a downloader), and any app that offers "sign out" or "clear browsing data".
Minimal repro: after signing in to a site that sets an HttpOnly session cookie, the app can't see that cookie.
func Browser(cx *core.Scope) core.Node {
web := &core.Ref{}
return core.View{Children: []core.Node{
core.WebView{Ref: web, Source: core.WebSrc("https://github.com/login")},
ui.Button{Text: "Read cookies", OnPress: func() {
web.Evaluate("document.cookie", func(json string, err error) {
// After signing in: user_session / __Host-user_session_same_site
// (HttpOnly) are missing, and there is no domain, path or expiry.
log.Println(json, err)
})
}},
}}
}Proposal
Every web view in the app shares the store, so this belongs on Scope as an asynchronous service, like ReadClipboard or PickFiles (core/services.go:128, 456), not on a Ref. It should work whether or not a web view is mounted at the time.
// WebCookie is a cookie in the app's web views' persistent store.
type WebCookie struct {
Name, Value string
Domain, Path string
Expires time.Time // zero for a session cookie
Secure bool
HTTPOnly bool
SameSite string // "", "Lax", "Strict" or "None"
}
// WebCookieFilter picks cookies: those a request to URL would send, or those of Domain and every host under it. The zero filter picks all.
type WebCookieFilter struct {
URL string
Domain string
}
// WebCookies lists the cookies of the app's web views, HttpOnly ones included, and calls done on the engine's goroutine.
func (cx *Scope) WebCookies(f WebCookieFilter, done func(cookies []WebCookie, err error))
// ClearWebsiteData removes everything the app's web views stored: cookies, local storage, IndexedDB, service workers and caches.
func (cx *Scope) ClearWebsiteData(done func(err error))Backends:
- Apple: list with
WKWebsiteDataStore.defaultDataStore.httpCookieStore getAllCookies:and filter in Go. Clear withremoveDataOfTypes:allWebsiteDataTypes modifiedSince:distantPast completionHandler:. - Windows: list with
GetCookies(uri)onICoreWebView2_2.CookieManager(an empty URI lists all). Clear withICoreWebView2Profile2.ClearBrowsingDataAll. WebView2 only exposes these from a liveICoreWebView2, so when no web view is mounted the backend can keep a hidden one in the shared profile. - Linux: list with
webkit_cookie_manager_get_all_cookies/webkit_cookie_manager_get_cookieson the session's existing cookie manager. Clear withwebkit_website_data_manager_clear(…, WEBKIT_WEBSITE_DATA_ALL, 0, …)on the manager fromwebkit_network_session_get_website_data_manager. - Android:
CookieManager.getCookie(url)returns only names and values. Either say so in the docs (fillDomainfrom the URL and leave the other fields empty) or failDomainfilters with anUnavailableerror. Clear withCookieManager.removeAllCookiesplusWebStorage.deleteAllData. - Web, tvOS, watchOS: fail with
core.Unavailable(core/errors.go:53), aserrNoInstallerdoes (core/services.go:725).
Both calls act on the persistent store only. Incognito views (#33 / #76) keep their data in memory, so they are out of scope, and the docs should say that.
Acceptance
- On macOS, Windows and Linux, a page in a
core.WebViewsets a cookie withSet-Cookie: s=1; HttpOnly; Secure; Path=/; Domain=example.test, andWebCookiesreturns it with every field filled in. - A
Domain: "example.test"filter returns cookies forexample.testandwww.example.testbut not forother.test. AURLfilter returns exactly the cookies a request to that URL would send. -
WebCookiesstill returns the cookie after the web view that set it has been unmounted, and after the app restarts (the persistent store). - After
ClearWebsiteData,WebCookiesreturns nothing, and a reloaded page sees emptylocalStorageand IndexedDB. -
doneruns on the engine's goroutine. On an unsupported target, both calls fail with anUnavailableerror instead of returning an empty list. - The gallery's WebView demo lists and clears cookies, and
docs/architecture/native-views.mdrecords the per-target matrix.
Activity
docs: bring the READMEs in line with the NSGo build
docs: bring the READMEs in line with the NSGo build (#123)
feat(core): list web view cookies and clear website data
feat(core): list web view cookies and clear website data
feat(core): list web view cookies and clear website data
feat(core): list web view cookies and clear website data
feat(core): list web view cookies and clear website data