CanSendCookie - never called

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.

CanSendCookie - never called

Postby Staxcelrom » Wed Jun 15, 2022 1:09 pm

Hello,

Why is CanSendCookie never called?

Code: Select all
class my_CEF_class__browser_ : ..., public CefCookieAccessFilter
{
    bool CanSendCookie(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request, const CefCookie& cookie) override
   {
      std::cout << "CanSendCookie" << std::endl;
      return true;
   }
}


But when loading the url then CanSendCookie() is never called.
Staxcelrom
Expert
 
Posts: 206
Joined: Wed Jan 26, 2022 8:20 am

Re: CanSendCookie - never called

Postby Staxcelrom » Thu Jun 16, 2022 12:52 am

GetCookieAccessFilter is called, but CanSendCookie still doesn't want to be called.
Staxcelrom
Expert
 
Posts: 206
Joined: Wed Jan 26, 2022 8:20 am

Re: CanSendCookie - never called

Postby magreenblatt » Thu Jun 16, 2022 2:48 am

What URL? Does DevTools Network tab show that cookies are being sent with the request?
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: CanSendCookie - never called

Postby Staxcelrom » Thu Jun 16, 2022 3:20 am

URL - youtube.com.

DevTools did not look, but in the HTTPS request headers in OnBeforeResourceLoad and in GetResourceResponseFilter - Cookies are present.
Staxcelrom
Expert
 
Posts: 206
Joined: Wed Jan 26, 2022 8:20 am

Re: CanSendCookie - never called

Postby amaitland » Thu Jun 16, 2022 3:49 am

I've had one report of cookies not being sent when cookie filter is used.

https://github.com/cefsharp/CefSharp/issues/4074

I suspect there's a bug in CEF/Chromium.
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1290
Joined: Wed Jan 14, 2015 2:35 am

Re: CanSendCookie - never called

Postby Staxcelrom » Thu Jun 16, 2022 4:59 am

magreenblatt wrote:What URL? Does DevTools Network tab show that cookies are being sent with the request?


URL - youtube.com.

In the HTTPS request headers in OnBeforeResourceLoad and in GetResourceResponseFilter - Cookies are present.

Checked devtools:

Code: Select all
   void OnLoadEnd(CefRefPtr< CefBrowser >browser, CefRefPtr< CefFrame >frame, int httpStatusCode) override
   {
            std::string my_method = "Network.getCookies";

            std::vector<std::string>method_param;
            method_param.push_back("array[ string ]");

            std::vector<std::string>method_param_value;
            method_param_value.push_back((*(*browser).GetMainFrame()).GetURL());

            my_generate_json_request(my_method , method_param);

           int ExecuteDevToolsMethod_STATUS_ = (*browser).GetHost()->SendDevToolsMessage(&my_method [0], my_method .size());
   }




Code: Select all
   class my_CefDevToolsMessageObserver_class : public CefDevToolsMessageObserver
{
      bool OnDevToolsMessage(CefRefPtr<CefBrowser> browser, const void* message, size_t message_size) override
      {
                         std::cout<<(char*)message<<std::endl;
      }
}


In OnDevToolsMessage - the result comes from the cookie.
That is, in DevTools - it works.

But CanSendCookie still doesn't want to be called.
Staxcelrom
Expert
 
Posts: 206
Joined: Wed Jan 26, 2022 8:20 am

Re: CanSendCookie - never called

Postby magreenblatt » Thu Jun 16, 2022 6:32 am

CanSendCookie will be called when loading a URL that will be sent cookies that already exist. It will not be called when loading the initial URL that sets the cookies. There is test coverage in https://github.com/chromiumembedded/cef ... nittest.cc
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: CanSendCookie - never called

Postby Staxcelrom » Thu Jun 16, 2022 7:39 am

magreenblatt wrote:CanSendCookie will be called when loading a URL that will be sent cookies that already exist. It will not be called when loading the initial URL that sets the cookies. There is test coverage in https://github.com/chromiumembedded/cef ... nittest.cc



I start CEF with the parameter:

Code: Select all
CefSettings settings;
CefString(&settings.cache_path) = my_string_path;
settings.persist_session_cookies = 1;


Next, I load the URL, after loading which I authorize on this URL. After that, Any navigation on this URL uses cookies, but CanSendCookie() - not called.
Staxcelrom
Expert
 
Posts: 206
Joined: Wed Jan 26, 2022 8:20 am

Re: CanSendCookie - never called

Postby Staxcelrom » Tue Jun 21, 2022 4:10 pm

CanSendCookie - guaranteed does not work in CEF.
Staxcelrom
Expert
 
Posts: 206
Joined: Wed Jan 26, 2022 8:20 am

Re: CanSendCookie - never called

Postby magreenblatt » Wed Jun 22, 2022 3:40 am

There is some test coverage for these methods, so they’re not completely broken. Maybe just with HTTPS requests or similar.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 40 guests