Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to clear cache / history webview2 #299

Closed
Spooninfotech opened this issue Jun 23, 2020 · 9 comments
Closed

How to clear cache / history webview2 #299

Spooninfotech opened this issue Jun 23, 2020 · 9 comments
Labels
feature request feature request tracked We are tracking this work internally.

Comments

@Spooninfotech
Copy link

Spooninfotech commented Jun 23, 2020

How to clear cache / history webview2?
I have a specific requirement not show the embedded Iframe history or in cache, which I can currently view under the "Cache" folder in the application installed directory created by the application.

AB#31044529

@michael-russin
Copy link

Not sure if you don't want to cache to disk at all or just clear the cache. If you just want to clear the cache data you can try using the appropriate CallDevToolsProtocolMethod

C++
m_coreWebView2->CallDevToolsProtocolMethod("Network.clearBrowserCache", "{}", handler);

or
.NET
_coreWebView2.CallDevToolsProtocolMethodAsync("Network.clearBrowserCache", "{}");

Chrome Dev Tools Protocol

@Spooninfotech
Copy link
Author

Spooninfotech commented Jun 23, 2020

Thanks the code worked to clear the Cache!
Also, I tried to disable cache following your helpful link, but it seems like the cache files are still created.
.NET
__coreWebView2.CallDevToolsProtocolMethodAsync("Network.setCacheDisabled", "{"cacheDisabled":true}");
image

@michael-russin
Copy link

There is also a flag I've used in the past in chrome that lets you reduce the size of the cache. It won't let you totally stop caching but if you make the cache size very small almost nothing gets cached. More of a hack than a solution.

 CoreWebView2EnvironmentOptions options = new CoreWebView2EnvironmentOptions("--disk-cache-size=1 ");
 Task<CoreWebView2Environment> task = CoreWebView2Environment.CreateAsync(null, cacheFolder, options);

Maybe InPrivate mode support would be a good feature request.

@Spooninfotech
Copy link
Author

@michael-russin I agree. InPrivate mode is required.

@Spooninfotech
Copy link
Author

Spooninfotech commented Jun 27, 2020

is there any way to add option to "disable context menu"?

CoreWebView2EnvironmentOptions options = new CoreWebView2EnvironmentOptions("--disk-cache-size=1");
var init = await CoreWebView2Environment.CreateAsync(null, localAppData + @"\EBWebView\Default\Cache", options);
await _webView2Control.EnsureCoreWebView2Async(init);
if (_webView2Control != null && _webView2Control.CoreWebView2 != null)
{
 _webView2Control.CoreWebView2.Settings.AreDefaultContextMenusEnabled = false;
}

context menu appear for a SECOND then goes off.

@michael-russin
Copy link

When are you setting the WebView2 Source property or calling WebView2.Navigate? CoreWebView2Settings states setting changes made after NavigationStarting event will not apply until the next top level navigation. Maybe a navigation is starting before you disable the context menu.

@champnic champnic added the feature request feature request label Dec 3, 2021
@sachin-jose
Copy link

I used these methods, and both didn't work for me (Network.clearBrowserCache and Network.setCacheDisabled). But I am able to clear cookies(credential data) by using 'Network.clearBrowserCookies'. Is there any option to delete/disable cache or session data. I am really looking forward for an answer for this.

@georg-eckert-zeiss
Copy link

georg-eckert-zeiss commented Mar 14, 2022

Same here. I used

_coreWebView2.CallDevToolsProtocolMethodAsync( "Network.setCacheDisabled", @"{""cacheDisabled"":true}" );

But cache still persisted. Do we have to do anything else?

Best regards.

PS: Could we get this through CoreWebView2Settings?

@champnic
Copy link
Member

champnic commented Feb 1, 2023

@champnic champnic closed this as completed Feb 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request feature request tracked We are tracking this work internally.
Projects
None yet
Development

No branches or pull requests

5 participants