Clear browsing data from the user data folder
To clear browsing data from the user data folder for a WebView2 app and free up space, call the methods of the Clear Browsing Data API.
The Clear Browsing Data API allows you to programmatically erase data in the user data folder that's associated with a WebView2 user profile. For example, use this API to clear user data and history when a user signs out.
You can:
- Clear all browsing data.
- Clear selected kinds of browsing data.
- Clear selected kinds of browsing data in a specified time range.
Clear all browsing data
This method clears all the kinds of browsing data that are listed in the data kinds enumeration, regardless of when the data was created. It clears the data from the user data folder for the user profile on which the method is called.
Clear selected kinds of browsing data
This method clears the specified kinds of browsing data, regardless of when the data was created. It clears the data from the user data folder for the user profile on which the method is called.
Clear selected kinds of browsing data in a time range
This method clears the specified kinds of browsing data that was created between the specified start time and end time. It clears the data from the user data folder for the user profile on which the method is called.
Example: Clearing selected kinds of browsing data in a time range
This example clears autofill data and password autosave data from the last hour.
The following parameter values are passed to the Clear Browsing Data API method:
The selected kinds of browser data = autofill data and password autosave data.
The specified time range = the past hour (3600 seconds).
// Clears autofill data.
private void ClearAutofillData()
{
CoreWebView2Profile profile;
if (webView.CoreWebView2 != null)
{
profile = webView.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);
await profile.ClearBrowsingDataAsync(dataKinds, startTime, endTime);
}
}
APIs:
API Reference
See also
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기