[reply]1.方法一
var options = new CoreWebView2EnvironmentOptions("--disk-cache-size=1 ");
string cacheDir = ".\\WebView2App.exe.WebView2";
var result = await CoreWebView2Environment.CreateAsync(null, cacheDir , options);
await webView21.EnsureCoreWebView2Async(result);
2.方法二
// Clears autofill data.
private async Task ClearAutofillData()
{
CoreWebView2Profile profile;
if (webView21.CoreWebView2 != null)
{
profile = webView21.CoreWebView2.Profile;
// Get the current time, the time in which the browsing data will be cleared
// until.
System.DateTime endTime = DateTime.Now;
System.DateTime startTime = DateTime.Now.AddHours(-1);
// Offset the current time by one hour to clear the browsing data from the
// last hour.
CoreWebView2BrowsingDataKinds dataKinds = (CoreWebView2BrowsingDataKinds)
(CoreWebView2BrowsingDataKinds.GeneralAutofill |
CoreWebView2BrowsingDataKinds.PasswordAutosave |
CoreWebView2BrowsingDataKinds.BrowsingHistory|
CoreWebView2BrowsingDataKinds.CacheStorage|
CoreWebView2BrowsingDataKinds.LocalStorage|
CoreWebView2BrowsingDataKinds.IndexedDb|
CoreWebView2BrowsingDataKinds.AllDomStorage|
CoreWebView2BrowsingDataKinds.Settings
//| CoreWebView2BrowsingDataKinds.Cookies
);
await profile.ClearBrowsingDataAsync(dataKinds, startTime, endTime);
}
}
3.方法三
var list = await webView21.CoreWebView2.CookieManager.GetCookiesAsync("https://www.douyin.com");
foreach (var item in list)
{
Console.WriteLine(item.Path + "," + item.Name);
}
var url = "https://www.douyin.com";
webView21.CoreWebView2.CookieManager.DeleteCookies("bd_ticket_guard_client_data", url );
webView21.CoreWebView2.CookieManager.DeleteCookies("passport_csrf_token", url);
webView21.CoreWebView2.CookieManager.DeleteCookies("ttwid", url );
webView21.CoreWebView2.CookieManager.DeleteCookies("__ac_signature", url);
webView21.CoreWebView2.CookieManager.DeleteCookies("home_can_add_dy_2_desktop", url);
webView21.CoreWebView2.CookieManager.DeleteCookies("strategyABtestKey", url);
webView21.CoreWebView2.CookieManager.DeleteCookies("_tea_utm_cache_2018", url);
webView21.CoreWebView2.CookieManager.DeleteCookies("__ac_nonce", url);
await ClearAutofillData();
webView21.CoreWebView2.Navigate("https://v.douyin.com/rVM32WM/");
4.方法四
await webView21.CoreWebView2.CallDevToolsProtocolMethodAsync("Network.clearBrowserCache", "{}");
5.方法五
await webView21.CoreWebView2.Profile.ClearBrowsingDataAsync();
[/reply]
1.方法一
var options = new CoreWebView2EnvironmentOptions("--disk-cache-size=1 ");
string cacheDir = ".\\WebView2App.exe.WebView2";
var result = await CoreWebView2Environment.CreateAsync(null, cacheDir , options);
await webView21.EnsureCoreWebView2Async(result);
2.方法二
// Clears autofill data.
private async Task ClearAutofillData()
{
CoreWebView2Profile profile;
if (webView21.CoreWebView2 != null)
{
profile = webView21.CoreWebView2.Profile;
// Get the current time, the time in which the browsing data will be cleared
// until.
System.DateTime endTime = DateTime.Now;
System.DateTime startTime = DateTime.Now.AddHours(-1);
// Offset the current time by one hour to clear the browsing data from the
// last hour.
CoreWebView2BrowsingDataKinds dataKinds = (CoreWebView2BrowsingDataKinds)
(CoreWebView2BrowsingDataKinds.GeneralAutofill |
CoreWebView2BrowsingDataKinds.PasswordAutosave |
CoreWebView2BrowsingDataKinds.BrowsingHistory|
CoreWebView2BrowsingDataKinds.CacheStorage|
CoreWebView2BrowsingDataKinds.LocalStorage|
CoreWebView2BrowsingDataKinds.IndexedDb|
CoreWebView2BrowsingDataKinds.AllDomStorage|
CoreWebView2BrowsingDataKinds.Settings
//| CoreWebView2BrowsingDataKinds.Cookies
);
await profile.ClearBrowsingDataAsync(dataKinds, startTime, endTime);
}
}
3.方法三
var list = await webView21.CoreWebView2.CookieManager.GetCookiesAsync("https://www.douyin.com");
foreach (var item in list)
{
Console.WriteLine(item.Path + "," + item.Name);
}
var url = "https://www.douyin.com";
webView21.CoreWebView2.CookieManager.DeleteCookies("bd_ticket_guard_client_data", url );
webView21.CoreWebView2.CookieManager.DeleteCookies("passport_csrf_token", url);
webView21.CoreWebView2.CookieManager.DeleteCookies("ttwid", url );
webView21.CoreWebView2.CookieManager.DeleteCookies("__ac_signature", url);
webView21.CoreWebView2.CookieManager.DeleteCookies("home_can_add_dy_2_desktop", url);
webView21.CoreWebView2.CookieManager.DeleteCookies("strategyABtestKey", url);
webView21.CoreWebView2.CookieManager.DeleteCookies("_tea_utm_cache_2018", url);
webView21.CoreWebView2.CookieManager.DeleteCookies("__ac_nonce", url);
await ClearAutofillData();
webView21.CoreWebView2.Navigate("https://v.douyin.com/rVM32WM/");
4.方法四
await webView21.CoreWebView2.CallDevToolsProtocolMethodAsync("Network.clearBrowserCache", "{}");
5.方法五
await webView21.CoreWebView2.Profile.ClearBrowsingDataAsync();