I want to allow cookies to persist in my app between sessions and am using this website to test my code. http://www.html-kit.com/tools/cookietester
In desktop Chrome, I can set a few cookies, close the Chrome and restart and they are still marked as present. In my app, I can set them and the page says they are set but when I restart my app, they are gone.
This behavior only appeared when I added my own implementation of CefRequestContextHandler and created my own cookie manaher with:
- Code: Select all
class ContextHandler :
public CefRequestContextHandler
{
public:
ContextHandler(const std::string cookieStorageDirectory)
{
bool persist_session_cookies = false;
CefRefPtr<CefCompletionCallback> callback = nullptr;
mCookieManager = CefCookieManager::CreateManager(CefString(cookieStorageDirectory), persist_session_cookies, callback);
}
CefRefPtr<CefCookieManager> GetCookieManager() override
{
return mCookieManager;
}
private:
CefRefPtr<CefCookieManager> mCookieManager;
IMPLEMENT_REFCOUNTING(ContextHandler);
};
and then refer to my context handler when I create my browser sync
- Code: Select all
CefRequestContextSettings contextSettings;
mContextHandler = new ContextHandler("cef_opengl_win_cookies");
CefRefPtr<CefRequestContext> request_context = CefRequestContext::CreateContext(contextSettings, mContextHandler.get());
mBrowser = CefBrowserHost::CreateBrowserSync(window_info, mBrowserClient.get(), gStartURL, browser_settings, request_context);
Previously, when I did not do this and just set the cache path setting, that website worked as expected.
I need my own cookie manager (I think) because I need it to set cookies programatically in my code elsewhere.
Interestingly, that website fails in the same way with CefClient - not sure if that's expected or not. I didn't see a cookie enabled/disabled setting.
What am I doing wrong (and should CefClient work like my desktop browser for that page?)