CefSharp Wpf , Session Cookie for multiple instances

6.4k views Asked by At

I am very curious if there is a possibility in CEF Sharp , somehow to isolate each instance of browser from other instances.

I am creating 4 instances of browser. Logging in on of the instances , immediately 3 other instances become logged in as well.

Is it possible to achieve somehow in Current version that we got from Nuget ?

2

There are 2 answers

2
Tobi Schweiger On

As of revision 2040, CEF now adds support for complete isolation of storage and permissions (cache, cookies, localStorage, access grants, etc) on a request context basis. This is also now in CEFSharp.

To make sure that no sessions overlap between multiple instances, simply create a new RequestContextSettings object, set PersistSessionCookies and/or PersistUserPreferences to false, and assign it to your browser while creating a new RequestContext - I am not sure if setting them to false is completely necessary for multiple instances, maybe someone else can give some info on that.

//usually ChromiumWebBrowser setup goes above this

RequestContextSettings requestContextSettings = new RequestContextSettings();

requestContextSettings.PersistSessionCookies = false;
requestContextSettings.PersistUserPreferences = false;

webBrowser.RequestContext = new RequestContext(requestContextSettings);

This had been giving me headaches for a while and this appears to finally solve that issue.

1
Sibghat Ullah On

Just use this code, its working for me.

public MainWindow()
    {
        CefSharp.CefSettings settings = new CefSharp.CefSettings();
        settings.CachePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\CEF"; 
       CefSharp.Cef.Initialize(settings);

        InitializeComponent();
        browser = new ChromiumWebBrowser("https://google.com/");
        browser.BrowserSettings.ApplicationCache = CefSharp.CefState.Disabled;

    }