Cookies not persisting?

Having problems with building or using the JCEF Java binding? Ask your questions here.

Cookies not persisting?

Postby JohnnyTheHun » Fri Jan 08, 2021 7:25 am

I am setting cookies from my web page which I would like to persist on disk.
What I did was set the cache_path when initialising CefApp.getInstance:
Code: Select all
CefSettings settings = new CefSettings();
File cachePath = new File(Modules.conf.userDir+"/cache");
cachePath.mkdirs();       
System.out.println("Setting cache path to: "+cachePath.getAbsolutePath());
settings.cache_path = cachePath.getAbsolutePath();
cefApp_ = CefApp.getInstance(settings);


I am able to visit cookies created on my website, but they do not get written to the disk. This worked before the cookie handling got revamped about a year ago. I was able to set cookie storage path via CefCookieManager.createManager(cookiePath, false); then.

Am I missing something, does something else need to be set also so cookies will be written to disk?
JohnnyTheHun
Techie
 
Posts: 42
Joined: Tue Apr 10, 2018 12:24 pm

Re: Cookies not persisting?

Postby magreenblatt » Fri Jan 08, 2021 2:39 pm

What OS and CEF version? Do you have a LocalPrefs.json file in your cache directory? See issue #2890 which may be related if you are using an old CEF version.
magreenblatt
Site Admin
 
Posts: 12379
Joined: Fri May 29, 2009 6:57 pm

Re: Cookies not persisting?

Postby JohnnyTheHun » Fri Jan 08, 2021 6:53 pm

I cloned the java-cef git repo a few days ago and implemented the getCookieManager function and I'm using the library I compiled according to the wiki. Everything is 64bit, building was done with 64bit.

JCEF Version = 87.1.12.275
CEF Version = 87.1.12
Chromium Version = 87.0.4280.88
OS: Windows 10 OS Version 2004 (Build 19041.685)
If I load the chrome:version in the browser the resulting list shows the cache path as empty

But I do set the cache path and it does create the folder and the folder does contain a LocalPrefs.json. I don't see any cookie files though.
I've attach the folder contents in a zip file to this message.

I use CefRequestContext.createContext(CefRequestContextHandler) to create the context.
Attachments
cache.zip
(2.16 KiB) Downloaded 586 times
JohnnyTheHun
Techie
 
Posts: 42
Joined: Tue Apr 10, 2018 12:24 pm

Re: Cookies not persisting?

Postby magreenblatt » Fri Jan 08, 2021 7:21 pm

How are you setting the cookies? Do they persist in Google Chrome and the cefclient sample application at the same version?
magreenblatt
Site Admin
 
Posts: 12379
Joined: Fri May 29, 2009 6:57 pm

Re: Cookies not persisting?

Postby JohnnyTheHun » Fri Jan 08, 2021 7:56 pm

I modified the detailed sample app to set a cache path in the settings for CefApp.getInstance(settings) and it also persisted the cookies.

What's interesting is that the sample application creates many more files in the cache path compared to what my app does in its cache path (see attached file in the post before).

E.g. my app creates the following files:
    LOG
    LOG.old
    LocalPrefs.json
    000003.log
    CURRENT
    MANIFEST-000001
    LOCK
    Visited Links

whilst the sample app:
    blob_storage\
    Cache\
    Code Cache\
    GPUCache\
    Local Storage\
    Session Storage\
    Cookies-journal
    Cookies
    Network Persistent State
    TransportSecurity
    LOG
    Visited Links
    LocalPrefs.json
    000003.log
    LOG.old
    CURRENT
    MANIFEST-000001
    LOCK
    Reporting and NEL-journal
    Reporting and NEL
JohnnyTheHun
Techie
 
Posts: 42
Joined: Tue Apr 10, 2018 12:24 pm

Re: Cookies not persisting?

Postby JohnnyTheHun » Mon Jan 18, 2021 7:28 am

I Have found what is causing this:

If I use a requestcontext to create a browser the cache folder has less files and folder than if I create a browser without a context.
Eg:

Code: Select all
  requestContext = CefRequestContext.createContext(this);
        browser_ = client_.createBrowser(startURL, useOSR, isTransparent,requestContext);

doesn't create the necessary files and cookies aren't persisted, while if I create the browser via:
Code: Select all
        browser_ = client_.createBrowser(startURL, useOSR, isTransparent);


It works. The problem for me is that I need different contexts for each browser AND I wan't cookies to persist. I cannot attain both in this jcef version.

Is this a bug?
JohnnyTheHun
Techie
 
Posts: 42
Joined: Tue Apr 10, 2018 12:24 pm

Re: Cookies not persisting?

Postby magreenblatt » Mon Jan 18, 2021 12:20 pm

You need to specify a cache path via CefRequestContextSettings.cache_path. Looks like that's not currently exposed via the JCEF API.
magreenblatt
Site Admin
 
Posts: 12379
Joined: Fri May 29, 2009 6:57 pm

Re: Cookies not persisting?

Postby JohnnyTheHun » Mon Jan 18, 2021 3:32 pm

I have implemented Vilsonai's solution from here:
https://www.magpcss.org/ceforum/viewtopic.php?t=17334

And it works.
He didn't implement the whole CefRequestContextSettings in java, he created a CefRequestContext.createContext(String cachePath, ...)

I will also try to add this in a PR when I figure out how to do that.

Cheers,
Janos
JohnnyTheHun
Techie
 
Posts: 42
Joined: Tue Apr 10, 2018 12:24 pm

Re: Cookies not persisting?

Postby JohnnyTheHun » Wed Jan 20, 2021 4:19 am

Marshall, I've noticed that if I create a new RequestContext (RQ2) but with the same cache path as a different RequestContext (RQ1) the cookie manager will be the same. E.g. If I set a cookie in RQ2 the same cookie will appear in RQ1.

Before the cookie manager overhaul I seem to remember that non persistant cookies (session cookies) could be different even if the cookie cache path was the same.

Is this the expected, normal behaviour?
JohnnyTheHun
Techie
 
Posts: 42
Joined: Tue Apr 10, 2018 12:24 pm

Re: Cookies not persisting?

Postby magreenblatt » Wed Jan 20, 2021 1:44 pm

Yes, that is expected. Separate cookie storage requires a separate RequestContext (either in-memory or a different cache_path).
magreenblatt
Site Admin
 
Posts: 12379
Joined: Fri May 29, 2009 6:57 pm


Return to JCEF Forum

Who is online

Users browsing this forum: No registered users and 2 guests