0

I have an application which uses CefSharp to access an internal web page. Once of the "tabs" on that internal web page loads up a third party website in an iFrame. That website has to ability to save some defaults. It does so by setting a cookie with an expiration date one month in the future. I would like to ignore that expiration date (or maybe continually change it). Is that something that's possible in CefSharp?

StarDestroyer
  • 63
  • 1
  • 8
  • From memory you'd visit the cookies for a url which basically gets you a list if you use the async extension method, then you can call setcookie modify the date see http://cefsharp.github.io/api/63.0.0/html/T_CefSharp_ICookieManager.htm – amaitland Jun 29 '18 at 02:09
  • 1
    https://github.com/cefsharp/CefSharp/blob/cefsharp/65/CefSharp.Example/Handlers/BrowserProcessHandler.cs#L32 has an example of visit url cookies. Visit simply refers to the visitor pattern used. – amaitland Jun 29 '18 at 02:11

1 Answers1

1

Thank-you, amaitland, for the pointer. For anybody else, this is what I ended up putting in my LoadingStateChanged routine (after I execute my JavaScript function):

cookieMgr.VisitUrlCookiesAsync("http://example.com", False) _
    .ContinueWith(Function(previous)
                      If previous.Status = TaskStatus.RanToCompletion Then
                          Dim cookies As List(Of Cookie) = previous.Result
                          For Each c As Cookie In cookies
                              If c.Name = "selectedLocation" Then
                                  c.Expires = DateTime.Now.AddYears(1)
                                  cookieMgr.SetCookieAsync("http://example.com", c)
                              End If
                          Next
                      End If
                      Return True
                  End Function)

I can't be sure that this is the best way to do it, but it looks like it's having the desired effect.

StarDestroyer
  • 63
  • 1
  • 8