Question Regarding Cookies and Multiple JCEF Instances

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

Question Regarding Cookies and Multiple JCEF Instances

Postby joxrox » Tue Sep 04, 2018 1:51 pm

Hello,

I am trying to create a program that uses multiple JCEF instances, each with their own unique cookie storage, to automate tasks on sites. So far, I have modified and built JCEF on so that the browsers run headlessly, but now I need each instance to have it's own cookie storage. Is this possible with the current builds of JCEF or will I need to make more modifications to the source code? If it is possible, can anyone give me a snippet of code that demonstrates how to do this?

Best regards,
Joe
joxrox
Newbie
 
Posts: 8
Joined: Thu May 10, 2018 8:12 am

Re: Question Regarding Cookies and Multiple JCEF Instances

Postby Czarek » Tue Sep 04, 2018 4:09 pm

In CEF to implement unique cookie managers you have to provide a unique CefRequestContext when creating browser and implement CefRequestHandler::GetCookieManager.
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: Question Regarding Cookies and Multiple JCEF Instances

Postby joxrox » Tue Sep 04, 2018 7:53 pm

Czarek wrote:In CEF to implement unique cookie managers you have to provide a unique CefRequestContext when creating browser and implement CefRequestHandler::GetCookieManager.


Thanks for your reply. I saw that in another forum post but I am having trouble understanding how to do this in Java since I am using JCEF. Do you think that I need to make changes to source code or can it be done in Java?
joxrox
Newbie
 
Posts: 8
Joined: Thu May 10, 2018 8:12 am

Re: Question Regarding Cookies and Multiple JCEF Instances

Postby Czarek » Wed Sep 05, 2018 12:04 am

Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: Question Regarding Cookies and Multiple JCEF Instances

Postby JohnnyTheHun » Sun Oct 14, 2018 3:39 am

You need something like this
Code: Select all
class MyReqContextHandler implements CefRequestContextHandler {
CefCookieManager cookieManager = null;
...
MyReqContextHandler() {
....
cookieManager = CefCookieManager.createManager(cookiePath, false);
....
}

public CefCookieManager getCookieManager() {
        return cookieManager;
}


}

MyReqContextHandler contextHandler = new MyReqContextHandler();
CefRequestContext requestContext = CefRequestContext.createContext(contextHandler);
CefBrowser browser_ = client_.createBrowser(url, useOSR, isTransparent,requestContext);

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

Re: Question Regarding Cookies and Multiple JCEF Instances

Postby JohnnyTheHun » Sun Feb 02, 2020 2:52 am

this no longer applies for newer versions of CEF. CefCookieManager.createManager was removed.
JohnnyTheHun
Techie
 
Posts: 42
Joined: Tue Apr 10, 2018 12:24 pm


Return to JCEF Forum

Who is online

Users browsing this forum: No registered users and 23 guests