Value of domain when setting cookie

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Value of domain when setting cookie

Postby callum » Mon Apr 11, 2016 8:35 pm

I have some code to saet a cookie that used to work - looks something like this:

Code: Select all
CefRefPtr<CefCookieManager> manager = mContextHandler->GetCookieManager();

CefString url = "https://my.example.com";

CefCookie cookie;
CefString(&cookie.name) = "cookie_name";
CefString(&cookie.value) = "cookie_value";
CefString(&cookie.domain) = "id.example.com";
CefString(&cookie.path) = "/";
cookie.httponly = false;
cookie.secure = true;
cookie.has_expires = false;

bool result = manager->SetCookie(url, cookie, nullptr);


It no longer works and nothing in my code has changed.

The result of setCookie(...) returns true but the cookie never appears in the cookie store. (Using sqlite3 to check).

If I change the domain parameter to "example.com" the cookie is appears.

The values are are all set to my code via a response from a REST call- I don't get to choose them myself - is the value I am getting for domain wrong or is there something else I need to do?
callum
Expert
 
Posts: 326
Joined: Mon Feb 23, 2015 6:19 pm

Re: Value of domain when setting cookie

Postby amaitland » Mon Apr 11, 2016 11:13 pm

You need to specify which versions it worked in and the version it doesn't work in now. Also any other background information that might be helpful.
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1292
Joined: Wed Jan 14, 2015 2:35 am

Re: Value of domain when setting cookie

Postby callum » Tue Apr 12, 2016 10:20 am

Urgh! My apologies - I always forget that.

Version 2526 Win32.

Nothing in my code changed - same version deployed as before when it worked as expected - that's what's so confusing.

I guess a good question is what happens in setCookie? It's possible that something changed with the URL/domain I am setting the cookie for but I have been unable to find out what so I'm trying to work backwards.
callum
Expert
 
Posts: 326
Joined: Mon Feb 23, 2015 6:19 pm

Re: Value of domain when setting cookie

Postby magreenblatt » Tue Apr 12, 2016 10:27 am

Your URL is "my.example.com" and domain is "id.example.com". Those don't match, so I wouldn't expect the cookie to be set. On the other hand, "example.com" will also match "my.example.com".
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Value of domain when setting cookie

Postby callum » Tue Apr 12, 2016 11:02 am

Shouldn't setCookie return false if the cookie cannot be set?

I'm having to do this somewhat convoluted process because other code POSTs data to a URL using C++/cURL and returns the information for me to set a cookie.

I see there is a CefPostData feature in CEF that I can use with LoadRequest() to POST data myself - will that set a cookie or do I still need to do it via setCookie?
callum
Expert
 
Posts: 326
Joined: Mon Feb 23, 2015 6:19 pm

Re: Value of domain when setting cookie

Postby magreenblatt » Tue Apr 12, 2016 11:09 am

callum wrote:Shouldn't setCookie return false if the cookie cannot be set?

Sure, but the actual implementation is asynchronous so we don't know if all aspects of the cookie are valid before the method returns. Currently we're only checking if the URL is valid: https://bitbucket.org/chromiumembedded/ ... mpl.cc-229
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Value of domain when setting cookie

Postby callum » Tue Apr 12, 2016 11:15 am

Ah - understood - makes sense.

Thank you.
callum
Expert
 
Posts: 326
Joined: Mon Feb 23, 2015 6:19 pm

Re: Value of domain when setting cookie

Postby callum » Tue Apr 12, 2016 3:43 pm

Follow up question relating to cookies.

I set cookies in my application during start up in the CEF store, call CefCookieManager::FlushStore(callback); afterwards and my callback is triggered.
I also have a callback set up to trigger when the setCookie call completes. Both callbacks happen almost instantly.

However, it takes something like 5-10 seconds for the cookie values to appear in the cookie file on disk (inspecting them with sqlite3).

This is a problem for me because shortly after my main app initializes, it loads a secondary DLL that displays web content which needs to read the cookie the main app just set.

Is there a way to force CEF to write things to disk so both processes can share the cookie without having to wait a long time?
callum
Expert
 
Posts: 326
Joined: Mon Feb 23, 2015 6:19 pm

Re: Value of domain when setting cookie

Postby magreenblatt » Wed Apr 13, 2016 1:26 am

Writing the cookies to disk quickly is not important for Chromium. I suggest you find a different way to share cookie info between processes. For example, use IPC.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Value of domain when setting cookie

Postby callum » Wed Apr 13, 2016 11:15 am

Understood.

However, in a simple test app, the cookie appears in the store immediately after the set/flush callbacks are triggered.

Is there something I'm maybe not doing that might explain the long delay? Perhaps not calling CefDoMessageLoopWork(); frequently enough at that point?
callum
Expert
 
Posts: 326
Joined: Mon Feb 23, 2015 6:19 pm

Next

Return to Support Forum

Who is online

Users browsing this forum: Majestic-12 [Bot] and 69 guests