3

I am trying to create separate user sessions per chromium browser instance but cannot find any relevant examples as to how. The purpose is to store cookies separately per browser instance.

Could anyone point me in the right direction? I would post relevant code but so far I only have basic examples from here.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
astralmaster
  • 2,344
  • 11
  • 50
  • 84

2 Answers2

3

CEF3 revision 2040 adds support for separated browser instances (cache, cookies, localStorage, access grants, etc). First, make sure you have the latest CefSharp (which is updated to CEF3.2526.1347).

Then as you can see in this example (line 135), just after your browser context is initialized in OnContextInitialized you can set the path for the cookie storage. The API for SetStoragePath is:

Sets the directory path that will be used for storing cookie data. If |path| is empty data will be stored in memory only. Returns false if cookies cannot be accessed.

So, you can experiment with in-memory cookies, or with a different path for each of your instances.

Sga
  • 3,608
  • 2
  • 36
  • 47
-1

As amaitland said, this is not supported.

To use proxies with CefSharp you can use this code, but the Initialize method can only be called once per application domain.

CefSettings settings = new CefSettings();
if (string.IsNullOrEmpty(proxyAddress) == false)
{
  settings.CefCommandLineArgs.Add("proxy-server", proxyAddress);
}
//validate if the CEF instance was already initialized
if (Cef.IsInitialized == false)
  Cef.Initialize(settings, true, true);
chromeBrowser = new ChromiumWebBrowser(url);

a workaround could be to use each WebBrowser instance on a different application and call it as a new process.

Hope this help

Roberto12cr
  • 15
  • 1
  • 10
  • A lot has changed since this question was asked, it's possible to isolate each browser instance, even have different proxy settings. The code your providing as reference looks very dated also as the method signatures have changed. – amaitland May 30 '17 at 21:32