chromiumembedded / cef

Chromium Embedded Framework (CEF). A simple framework for embedding Chromium-based browsers in other applications.
https://bitbucket.org/chromiumembedded/cef/
Other
3.28k stars 456 forks source link

cannot get cookies #3599

Closed warsark closed 10 months ago

warsark commented 10 months ago

cef_binary_118.6.10+g38848f1+chromium-118.0.5993.119_windows32 windows 11 22h2 64

` CefRefPtr ClientHandler::GetResourceHandler( CefRefPtr browser, CefRefPtr frame, CefRefPtr request) { CEF_REQUIRE_IO_THREAD();

return new WebResourceHandler(browser, frame, handler); }

class WebResourceHandler : public CefResourceHandler { ... };

class WebRequestClient : public CefURLRequestClient { ... };

bool WebResourceHandler::ProcessRequest(CefRefPtr request, CefRefPtr callback) { cef_urlrequest_flags_t urlRequestFlags = UR_FLAG_ALLOW_STORED_CREDENTIALS; //request->SetFlags(urlRequestFlags);//crash request is readonly m_webRequestClient = new WebRequestClient(m_frame); m_webRequest = CefURLRequest::Create(request, m_webRequestClient.get(), nullptr); return true; }

void WebRequestClient::OnRequestComplete(CefRefPtr request) { auto statusCode = request->GetRequestStatus(); if (statusCode == CefURLRequest::Status::UR_SUCCESS) { //1.use header map get cookie fail! auto response = request->GetResponse(); CefResponse::HeaderMap headerMap; response->GetHeaderMap(headerMap); //the headerMap not contains Set-Cookie

//2.use cookie manager fail CefRefPtr cefCookieManager = CefCookieManager::GetGlobalManager(nullptr); CefRefPtr event = CefWaitableEvent::CreateWaitableEvent(true, false); CookieVector cookies; cefCookieManager->VisitAllCookies(new myCookieVisitor(&cookies, false, std::move(base::BindOnce(&CefWaitableEvent::Signal, event)))); event->Wait();// crash } }

class myCookieVisitor : public CefCookieVisitor { bool Visit(const CefCookie& cookie, int count, int total, bool& deleteCookie) override { //not execute!!! } }; `

magreenblatt commented 10 months ago

With CefURLRequest you need to set the UR_FLAG_ALLOW_STORED_CREDENTIALS flag prior to starting the request. With normal requests you need to use CefCookieManager. Please use the CEF Forum for questions in the future.