Can't get SetCookie working via Task from render thread

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.

Can't get SetCookie working via Task from render thread

Postby HarmlessDave » Tue Aug 26, 2014 6:39 pm

There aren't any examples of using CefCookieManager::SetCookie in CefClient or the General Usage page, and a forum search didn't turn up anything quite like what I'm trying to do.

I want to detect that the next navigation is to a page that I care about, and if so to set an in-memory cookie. This is what I've tried in CefClient - client_app.cc, but it just kills the render process:

Code: Select all
#include "include/cef_runnable.h"

bool ClientApp::OnBeforeNavigation(CefRefPtr<CefBrowser> browser,
                                   CefRefPtr<CefFrame> frame,
                                   CefRefPtr<CefRequest> request,
                                   NavigationType navigation_type,
                                   bool is_redirect) {

   // set cookie if dell.com - home - laptops (http://www.dell.com/us/p/laptops.aspx?~ck=mn)
   std::string strURL = request->GetURL();
   if (strURL.find("dell.com") != std::string::npos && strURL.find("laptops") != std::string::npos)
   {
      //      CefRefPtr<CefCookieManager> cookie_manager = CefCookieManager::GetGlobalManager();
      CefCookieManager* cookie_manager = CefCookieManager::GetGlobalManager();
      CefCookie cookie;
      CefString(&cookie.name).FromASCII("testname");
      CefString(&cookie.value).FromASCII("testval");
      BOOL okc = CefPostTask(TID_IO, NewCefRunnableMethod(cookie_manager, &CefCookieManager::SetCookie, strURL, cookie));   // async so true response not reliable
      // ** above terminates render thread **
   }

...


Can anyone point out what I'm doing wrong? (Or can you supply a working example?)

Can I do this with JavaScript instead, *in this event*? A sample of that would be very helpful too. I just need to set an in-memory cookie here, I don't care how :)
HarmlessDave
Expert
 
Posts: 370
Joined: Fri Jul 11, 2014 2:02 pm

Re: Can't get SetCookie working via Task from render thread

Postby magreenblatt » Wed Aug 27, 2014 3:48 pm

CefCookieManager can only be used in the browser process. There are examples here: https://code.google.com/p/chromiumembed ... nittest.cc
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 68 guests