Answer the question
In order to leave comments, you need to log in
Why is recovering cookies (from Json) in CefSharp not working as it should?
void SaveCookies()
{
var cv = new CookieVisitor();
Cef.GetGlobalCookieManager().VisitAllCookies(cv);
var json = JsonConvert.SerializeObject(cv.Cookies);
File.WriteAllText(settingsPath, json);
}
void SetCookies()
{
var json = File.ReadAllText(settingsPath);
var cookies = JsonConvert.DeserializeObject<List<Cookie>>(json);
if (cookies == null || cookies.Count == 0)
return;
foreach(var cookie in cookies)
{
Cef.GetGlobalCookieManager().SetCookie(cookie.Domain, cookie);
}
}
class CookieVisitor : ICookieVisitor
{
public List<Cookie> Cookies { get; set; }
public CookieVisitor()
{
Cookies = new List<Cookie>();
}
public void Dispose()
{
}
public bool Visit(Cookie cookie, int count, int total, ref bool deleteCookie)
{
if (cookie == null)
return false;
Cookies.Add(cookie);
return true;
}
}
Cef.GetGlobalCookieManager().VisitAllCookies(cv);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question