I am developing an app on a banking device that uses cefsharp browser as a part of it. Cause this app will be used by anyone it should not save any data from previous user that the next user can see. I want to clear all cached browser data after closing it.
public void InitBrowser()
{
settings = new CefSettings();
settings.CachePath = AppDomain.CurrentDomain.BaseDirectory + "cache";
settings.CefCommandLineArgs.Add("disable-application-cache", "1");
settings.CefCommandLineArgs.Add("disable-session-storage", "1");
if (!Cef.IsInitialized) Cef.Initialize(settings);
webBrowser = new CefSharp.Wpf.ChromiumWebBrowser();
MainGrid.Children.Add(webBrowser);
}
I want to clear all cached data after a function named WebPages_Exit
is called. How can I remove all cached data without removing the browser instance or shutting down the CEF cause CEF can't be initialized twice and creating another instance of browser after disposing it is not working.
I implemented visit
function in ICookieVisitor
to save cookies as well and used methods like deleteCookies
or disabling cache cefSetting command, but nothing works cause cookies list is empty and visit
function of IcookieVisitor
is never called. it seems that it is saved in another part and just resets when CEF will shutdown.
I found the answer! It was because of disabling cache setting.
By doing so, it actually caches the data but it won't be accessible. For example, you can't remove cookies without shutting down CEF
. So, if you enable cache setting (leave it as the default), you can remove them with Cef.GetGlobalCookieManager().DeleteCookies("", "")
.
You can delete cache folders before calling Cef.Initialize
:
Directory.Delete(cacheDirBase + "\\blob_storage", true);
Directory.Delete(cacheDirBase + "\\Cache", true);
Directory.Delete(cacheDirBase + "\\Code Cache", true);
Directory.Delete(cacheDirBase + "\\GPUCache", true);
Directory.Delete(cacheDirBase + "\\Local Storage", true);
Directory.Delete(cacheDirBase + "\\Session Storage", true);
Just remove whichever you don't want to delete.
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