SOLVED: CefCookieManager.setCookie() is not working

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

SOLVED: CefCookieManager.setCookie() is not working

Postby JCEFBeginner » Tue Jul 20, 2021 10:21 am

Hello,

in my JCEF Application, setting a cookie with
Code: Select all
CefCookieManager.getGlobalManager().setCookie();
is not working.

For demonstration, I created a little code snippet:
Code: Select all
CefApp.startup(new String[0]);
        CefApp app = CefApp.getInstance();
        CefClient client = app.createClient();
        CefBrowser browser = client.createBrowser("www.google.de", OS.isLinux(), false);
        JFrame frame = new JFrame();
        frame.setVisible(true);
        JPanel panel = new JPanel();
        frame.add(panel);
        panel.add(browser.getUIComponent());

        CefCookie cookie = new CefCookie("test", "123456", "www.google.de", "/", false, false, null, null, false, null);
        CefCookieManager manager = CefCookieManager.getGlobalManager();
        manager.setCookie("about:blank", cookie);
        manager.visitAllCookies((cookie1, count, total, delete) -> {
            System.out.println(cookie1.name + '=' + cookie1.value);
            return true;
        });
The code is not writing a cookie to console.
Last edited by JCEFBeginner on Tue Jul 20, 2021 1:58 pm, edited 1 time in total.
JCEFBeginner
Techie
 
Posts: 18
Joined: Fri Feb 12, 2021 12:17 pm

Re: CefCookieManager.setCookie() is not working

Postby magreenblatt » Tue Jul 20, 2021 10:22 am

Cookies are restricted by URL/origin. The URL passed to setCookie must match the domain/origin of the cookie.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: CefCookieManager.setCookie() is not working

Postby JCEFBeginner » Tue Jul 20, 2021 1:58 pm

Thank you, @magreenblatt.
It works :)
The problem was, that the value of secure was set to true.
JCEFBeginner
Techie
 
Posts: 18
Joined: Fri Feb 12, 2021 12:17 pm


Return to JCEF Forum

Who is online

Users browsing this forum: No registered users and 20 guests