Separate cookie manager for each browser instance.

46 views
Skip to first unread message

laserma...@gmail.com

unread,
Nov 7, 2016, 6:49:16 AM11/7/16
to CefGlue
I am trying to achieve the following :

I have 3 browser instances opened in Wpf application.
When I am logging in on one of the opened intstances all 3 of them , immediately loggin in as well.

How can I achieve the situation , that each instance of the browser will have own session cookie manager.

Appreciate a lot any possible help.

Dmitry Azaraev

unread,
Nov 7, 2016, 7:31:27 AM11/7/16
to CefGlue

You need provide separate CefRequestContext for each browser instance (during browser creation) with own CefCookieManager.


--
You received this message because you are subscribed to the Google Groups "CefGlue" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cefglue+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

laserma...@gmail.com

unread,
Nov 7, 2016, 8:11:31 AM11/7/16
to CefGlue, dmitry....@gmail.com
Dmitriy , many thanks for so fast reply.
Any chance you can explain in few lines , what will be the best way to achieve this ? 

In WpfCefBrowser.cs there is a line 

 // This is the first time the window is being rendered, so create it.
CefBrowserHost.CreateBrowser(windowInfo, _cefClient, settings, !string.IsNullOrEmpty(StartUrl) ? StartUrl : "about:blank", <<Here I can Pass Request Context ?>>);

All classes related for CefRequestContext are sealed , I am appologize for being a full Dumb , but please if it's not hard , few lines of detailed explanation can help me.

Dmitry Azaraev

unread,
Nov 7, 2016, 8:27:22 AM11/7/16
to CefGlue
Yes, request contest should be passed into CefBrowserHost.CreateBrowser. It is easy actually.

So, what you need:

0. Write MyRequestContextHandler class (derive it from CefRequestContextHandler). It should provide concrete cookie manager, so it can accept CefCookieManager in constructor, and return it in overriden method (GetCookieManager).

2. Create cookie manager with CefCookieManager::Create.
3. Create MyRequestContextHandler with cookie manager from step 2.
4. Create request context with CefRequestContext::CreateContext with desired settings and request context handler from step 3.

Note about request context settings - cache path - null/emtpy is in-memory cache. If you want share on-disk cache, this also imply that you will share pesisted local storage / etc stuff, what actually will work wrong with different cookie managers (other users may read other users data), so keep per-browser unique cache paths or use in-memory if cache persistence is not required.

laserma...@gmail.com

unread,
Nov 7, 2016, 8:55:31 AM11/7/16
to CefGlue
Dima , so many thanks to you !!! It's working !!!
Reply all
Reply to author
Forward
0 new messages