CoreWebView2Profile Class

Multiple profiles can be created under a single user data directory but with separated cookies, user preference settings, and various data storage etc.. If the CoreWebView2 was created with a CoreWebView2ControllerOptions, the CoreWebView2Profile will match those specified options. Otherwise if this CoreWebView2 was created without a CoreWebView2ControllerOptions, then this will be the default CoreWebView2Profile for the corresponding CoreWebView2Environment.

Summary

Members Description
DefaultDownloadFolderPath The default download folder path.
IsInPrivateModeEnabled InPrivate mode is enabled or not.
PreferredColorScheme The PreferredColorScheme property sets the overall color scheme of the WebView2s associated with this profile.
PreferredTrackingPreventionLevel The PreferredTrackingPreventionLevel property allows you to control levels of tracking prevention for WebView2 which are associated with a profile. This level would apply to the context of the profile. That is, all WebView2s sharing the same profile will be affected and also the value is persisted in the user data folder.
ProfileName The name of the profile.
ProfilePath Full path of the profile directory.
ClearBrowsingDataAsync Clears browsing data for dataKinds between startTime and endTime.
ClearBrowsingDataAsync Clears all browsing data associated with the profile this method is called on regardless of timestamp.
ClearBrowsingDataAsync Clear the browsing data of the associated profile.

Properties

DefaultDownloadFolderPath

string DefaultDownloadFolderPath

The default download folder path. The default value is the system default download folder path for the user. The default download folder path is persisted in the user data folder across sessions. The value should be an absolute path to a folder that the user and application can write to. Throws an exception if the value is invalid, and the default download path is not changed. Otherwise the path is changed immediately. If the directory does not yet exist, it is created at the time of the next download. If the host application does not have permission to create the directory, then the user is prompted to provide a new path through the Save As dialog. The user can override the default download folder path for a given download by choosing a different path in the Save As dialog.

IsInPrivateModeEnabled

readonly bool IsInPrivateModeEnabled

InPrivate mode is enabled or not.

PreferredColorScheme

CoreWebView2PreferredColorScheme PreferredColorScheme

The PreferredColorScheme property sets the overall color scheme of the WebView2s associated with this profile. This sets the color scheme for WebView2 UI like dialogs, prompts, and menus by setting the media feature prefers-color-scheme. The default value for this is CoreWebView2PreferredColorScheme.Auto, which will follow whatever color scheme the OS is currently set to.

PreferredTrackingPreventionLevel

CoreWebView2TrackingPreventionLevel PreferredTrackingPreventionLevel

The PreferredTrackingPreventionLevel property allows you to control levels of tracking prevention for WebView2 which are associated with a profile. This level would apply to the context of the profile. That is, all WebView2s sharing the same profile will be affected and also the value is persisted in the user data folder.

See CoreWebView2TrackingPreventionLevel for descriptions of levels. If tracking prevention feature is enabled when creating the WebView2 environment, you can also disable tracking prevention later using this property and CoreWebView2TrackingPreventionLevel.None value but that doesn't improves runtime performance.

There is CoreWebView2EnvironmentOptions.EnableTrackingPrevention property to enable/disable tracking prevention feature for all the WebView2's created in the same environment. If enabled, PreferredTrackingPreventionLevel is set to CoreWebView2TrackingPreventionLevel.Balanced by default for all the WebView2's and profiles created in the same environment or is set to the level whatever value was last changed/persisted to the profile. If disabled PreferredTrackingPreventionLevel is not respected by WebView2. If PreferredTrackingPreventionLevel is set when the feature is disabled, the property value get changed and persisted but it will takes effect only if CoreWebView2EnvironmentOptions.EnableTrackingPrevention is true.

See CoreWebView2EnvironmentOptions.EnableTrackingPrevention for more details.

ProfileName

readonly string ProfileName

The name of the profile.

ProfilePath

readonly string ProfilePath

Full path of the profile directory.

Methods

ClearBrowsingDataAsync

IAsyncAction ClearBrowsingDataAsync(CoreWebView2BrowsingDataKinds dataKinds, DateTime startTime, DateTime endTime)

Clears browsing data for dataKinds between startTime and endTime.

ClearBrowsingDataAsync

IAsyncAction ClearBrowsingDataAsync()

Clears all browsing data associated with the profile this method is called on regardless of timestamp.

ClearBrowsingDataAsync

IAsyncAction ClearBrowsingDataAsync(CoreWebView2BrowsingDataKinds dataKinds)

Clear the browsing data of the associated profile. Clears browsing data on the profile the method is called on. Additional optional parameters include the start time and end time to clear the browsing data between as well as the data specific data kinds to clear on the profile. The method may be overloaded to take:

  • No parameters - in which the entirety of the data on the profile will be cleared.
  • The data kind(s) - in which the data kind(s) will be cleared for their entirety.
  • The data kind(s), start time, and end time - in which the data kind(s) will be cleared between the start and end time. The start time will be offset by -1.0 and the end time will be offset by +1.0 to include the last fractional second on each respective end. The start time is inclusive in the time period while the end time is exclusive.

The exposed methods are as follows:

ClearBrowsingDataAsync(CoreWebView2BrowsingDataKinds dataKinds);
ClearBrowsingDataAsync(CoreWebView2BrowsingDataKinds dataKinds, DateTime startTime, DateTime endTime);
ClearBrowsingDataAsync();

Referenced by