Hello,
I'm having a hard time getting this to work reliably with CefGlue. I want to run VisitUrlCookies to get all cookies. Based on a suggestion in some other posts, it looks like the Visit method in my CefCookieVisitor will be called repeatedly, and once all of the cookies are found, the Dispose method will be called. What I find is that this seems to be unreliable. I'm finding that the Visit method is being called for the cookies (of which there is only one), but once that has happened, the Dispose method isn't always called. Some of the time it is called ok, but in other cases, it isn't called. Here is the code for my visitor:
namespace MyCookieVisitor
{
using System.Net;
using System.Threading.Tasks;
using Xilium.CefGlue;
internal class CookieVisitor : CefCookieVisitor
{
private TaskCompletionSource<CookieCollection> completionSource;
public CookieVisitor()
{
this.Cookies = new CookieCollection();
}
public CookieCollection Cookies { get; private set; }
protected override bool Visit(CefCookie cookie, int count, int total, out bool delete)
{
this.Cookies.Add(new Cookie(cookie.Name, cookie.Value, cookie.Path, cookie.Domain));
delete = false;
return true;
}
public void GetCookies(string address, TaskCompletionSource<CookieCollection> completionSource)
{
CefCookieManager.GetGlobal(null).VisitUrlCookies(address, false, this);
this.completionSource = completionSource;
}
protected override void Dispose(bool disposing)
{
this.completionSource.SetResult(this.Cookies);
}
}
}
Is there anything wrong with what I'm doing here?