Currently I'm setting the cache path as follows:
CefSettings settings = new CefSettings();
settings.CachePath = mycachePath;
Cef.Initialize(settings);
var browser = new ChromiumWebBrowser(myUrl);
The above works.
However, I need to login to a website with 2 different accounts simultaneously but it uses the same cookie container. So if I login with one account and then the other, the first account is overridden.
Is it possible to have a have a cache path per browser?
Or is there a better way to handle this situation?
Each browser application (Internet Explorer, Google Chrome, Mozilla Firefox, Apple Safari) maintains its own set of “cached” files and cookies. Each browser's cache may have many thousands of files. Each browser's cookie store may have scores of cookies.
Here's how to clear the browser cache for just one web page: Open the webpage you want to clear the cache for, and go into Chrome Developer Tools. That's CMD+Option+I on a Mac, and CTRL+Shift+I or F12 on Windows, Linux, and Chromebooks. Click Empty Cache and Hard Reload in the list of options, and you're done.
Launch Safari browser on your Mac. Click the Privacy tab and select Manage Website Data.... Select a website that is listed, then click Remove.
Click the Tools menu (three dotted lines in the upper-right corner), and open the Settings menu. Click Privacy, search, and services on the left-side menu. Under the section Clear browsing data, click Choose what to clear. Select Cookies and other site data and Cached images and files.
It looks like you're using CefSharp? If so, looking through the code, it seems that you want to create the browser with an empty CachePath:
/// <summary>
/// Returns the cache path for this object. If empty an "incognito mode"
/// in-memory cache is being used.
/// </summary>
string CachePath { get; }
Looking at their sample (I'm assuming windowless), this looks like it'll get roughly what you want:
var browserSettings = new BrowserSettings();
var requestContextSettings = new RequestContextSettings { CachePath = "" };
using(var requestContext = new RequestContext(requestContextSettings))
using (var browser = new ChromiumWebBrowser(TestUrl, browserSettings, requestContext))
{
...
}
This is old, but I just came across it and it needs a more complete answer. You can have as many browser instances open as you want, each with its own separate cache & cookies that are independent of the others. All you have to do is set the CachePath
settings property for each browser, making sure its path is distinct, and then create the browser.
An example scenario in which you might use this is with tabs, where Tab1 has Browser1, Tab2 has Browser2, etc. and each browser instance has no knowledge of the others. That is achieved by giving each browser its own cache path before creating it.
In VB .NET:
CEFPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\My\Special\Cache\Path"
If Not Directory.Exists(CEFPath) Then
Try
Directory.CreateDirectory(CEFPath)
Catch ex As Exception
MsgBox("Error creating cache directory" + vbCrLf + CEFPath,, "Error")
End Try
End If
Dim settings As New CefSettings()
settings.CachePath = CEFPath
'Settings.Proxy = new ProxyOptions(ip: "myipaddress", port: "myport", username: "myusername", password: "mypassword")
' initialization before creating instance
If CefSharp.Cef.IsInitialized = False Then
CefSharp.Cef.Initialize(settings)
End If
browser = New ChromiumWebBrowser("")
Dim requestContextSettings As New RequestContextSettings()
requestContextSettings.CachePath = CEFPath
'Optional:
requestContextSettings.PersistSessionCookies = True
'https://github.com/cefsharp/CefSharp/wiki/General-Usage
browser.RequestContext = New RequestContext(requestContextSettings)
I am using NuGet packages v83.4.20
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With