{"record":{"id":"d3db0d24e3579a73","repo":"GopeedLab/gopeed","slug":"native-cookie-access-is-unavailable","errorCode":null,"errorMessage":"native cookie access is unavailable","messagePattern":"native cookie access is unavailable","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/webview/goprovider/provider.go","lineNumber":259,"sourceCode":"\t\t}\n\t\tif cookie.Expires != \"\" {\n\t\t\tif parsed, err := time.Parse(time.RFC3339Nano, cookie.Expires); err == nil {\n\t\t\t\titem.Expires = parsed\n\t\t\t}\n\t\t}\n\t\tresult = append(result, item)\n\t}\n\treturn result, nil\n}\n\nfunc (p *pageWrapper) SetCookie(cookie enginewebview.Cookie) error {\n\ttype cookieSetter interface {\n\t\tSetCookie(cookie webview.Cookie) error\n\t}\n\treturn p.dispatch(func(w webview.WebView) error {\n\t\tsetter, ok := w.(cookieSetter)\n\t\tif !ok {\n\t\t\treturn fmt.Errorf(\"native cookie access is unavailable\")\n\t\t}\n\t\treturn setter.SetCookie(webview.Cookie{\n\t\t\tName:     cookie.Name,\n\t\t\tValue:    cookie.Value,\n\t\t\tDomain:   cookie.Domain,\n\t\t\tPath:     cookie.Path,\n\t\t\tExpires:  cookie.Expires,\n\t\t\tSecure:   cookie.Secure,\n\t\t\tHTTPOnly: cookie.HTTPOnly,\n\t\t})\n\t})\n}\n\nfunc (p *pageWrapper) DeleteCookie(cookie enginewebview.Cookie) error {\n\ttype cookieDeleter interface {\n\t\tDeleteCookie(name string, domain string, path string) error\n\t}\n\treturn p.dispatch(func(w webview.WebView) error {","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/GopeedLab/gopeed/blob/7b7327ffb30816273a74b142cccc0bc10c5a4c67/internal/webview/goprovider/provider.go#L241-L277","documentation":"SetCookie is an optional capability. The provider type-asserts the underlying webview.WebView to a private cookieSetter interface (SetCookie(webview.Cookie) error); when the concrete binding does not implement it, the assertion fails and this error returns. It is a feature probe, not a runtime fault — the webview itself is fine.","triggerScenarios":"Calling SetCookie on a platform whose webview_go binding was built without the cookie extension; custom embedders that wrap or replace the native webview object and thereby hide the interface.","commonSituations":"Cross-platform code that worked on a patched build (e.g. one exposing SetCookie for WebView2) and then fails on stock upstream webview bindings; users migrating to a provider build with fewer native extensions.","solutions":["Fall back to setting cookies through JS: page.Execute with document.cookie","Feature-detect once at startup (try a benign SetCookie) and remember the capability","If native cookies are required, build/upgrade the webview binding so it implements the cookieSetter interface"],"exampleFix":"// before\nerr := page.SetCookie(cookie) // \"native cookie access is unavailable\"\n\n// after\nif err := page.SetCookie(cookie); err != nil {\n    _, err = page.Execute(fmt.Sprintf(\n        `() => { document.cookie = %q=%q; Path=%s; Domain=%s; }`,\n        cookie.Name, cookie.Value, cookie.Path, cookie.Domain))\n}","handlingStrategy":"fallback","validationCode":"// Probe native cookie support once, then route accordingly\nvar nativeCookies bool\n\nfunc detectCookieSupport(page enginewebview.Page) bool {\n    return page.SetCookie(enginewebview.Cookie{Name: \"__probe\", Value: \"1\", Path: \"/\"}) == nil\n}","typeGuard":"// Go's idiom for this probe is interface assertion (as the provider itself does):\ntype cookieSetter interface {\n    SetCookie(cookie webview.Cookie) error\n}\n\nfunc hasNativeSetCookie(w webview.WebView) bool {\n    _, ok := w.(cookieSetter)\n    return ok\n}","tryCatchPattern":"if err := page.SetCookie(cookie); err != nil {\n    if strings.Contains(err.Error(), \"native cookie access is unavailable\") {\n        return setCookieViaJS(page, cookie) // document.cookie fallback\n    }\n    return err\n}","preventionTips":["Feature-detect cookie APIs at startup and cache the result per provider build","Keep a JS-based cookie helper as the portable default","Do not assume desktop-browser cookie semantics in embedded webviews"],"tags":["webview","cookies","capability","feature-detect"],"backgroundTag":null,"analyzedSha":"7b7327ffb30816273a74b142cccc0bc10c5a4c67","analyzedAt":"2026-08-16T02:51:03.250Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}