Class CoreWebView2Profile
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.
public class CoreWebView2Profile
- Inheritance
-
CoreWebView2Profile
- Inherited Members
Properties
CookieManager
Get the CoreWebView2CookieManager which Creates, adds or updates, gets, or or view the cookies for the current profile.
public CoreWebView2CookieManager CookieManager { get; }
Property Value
Remarks
All CoreWebView2s associated with this profile share the same cookie values. Changes to cookies in this cookie manager apply to all CoreWebView2s associated with this profile.
- See Also
DefaultDownloadFolderPath
The default download folder path.
public string DefaultDownloadFolderPath { get; set; }
Property Value
Remarks
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.
IsGeneralAutofillEnabled
Determines whether general form information will be saved and autofilled.
public bool IsGeneralAutofillEnabled { get; set; }
Property Value
Remarks
General autofill information includes information like names, street and email addresses, phone numbers, and arbitrary input. This excludes password information. When disabled, no suggestions appear, and no new information is saved.
When enabled, information is saved, suggestions appear, and clicking on one will populate the form fields. The default value is true
. It will apply immediately after setting.
This property has the same value as IsGeneralAutofillEnabled, and changing one will change the other. All WebView2s with the same CoreWebView2Profile will share the same value for this property, so for the WebView2s with the same profile, their IsGeneralAutofillEnabled and IsGeneralAutofillEnabled will always have the same value.
IsInPrivateModeEnabled
InPrivate mode is enabled or not.
public bool IsInPrivateModeEnabled { get; }
Property Value
IsPasswordAutosaveEnabled
Determines whether password information will be autosaved.
public bool IsPasswordAutosaveEnabled { get; set; }
Property Value
Remarks
When disabled, no new password data is saved and no Save/Update Password prompts are displayed. However, if there was password data already saved before disabling this setting, then that password information is auto-populated, suggestions are shown and clicking on one will populate the fields.
When enabled, password information is auto-populated, suggestions are shown and clicking on one will populate the fields, new data is saved, and a Save/Update Password prompt is displayed. The default value is false
. It will apply immediately after setting.
This property has the same value as IsPasswordAutosaveEnabled, and changing one will change the other. All WebView2s with the same CoreWebView2Profile will share the same value for this property, so for the WebView2s with the same profile, their IsPasswordAutosaveEnabled and IsPasswordAutosaveEnabled will always have the same value.
PreferredColorScheme
The PreferredColorScheme property sets the overall color scheme of the WebView2s associated with this profile.
public CoreWebView2PreferredColorScheme PreferredColorScheme { get; set; }
Property Value
Remarks
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 Auto, which will follow whatever color scheme the OS is currently set to.
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.
public CoreWebView2TrackingPreventionLevel PreferredTrackingPreventionLevel { get; set; }
Property Value
Remarks
If tracking prevention feature is enabled when creating the WebView2 environment, you can also disable tracking prevention later using this property and None value but that doesn't improves runtime performance.
There is EnableTrackingPrevention property to enable/disable tracking prevention feature for all the WebView2's created in the same environment. If enabled, PreferredTrackingPreventionLevel
is set to 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 EnableTrackingPrevention is true.
See EnableTrackingPrevention for more details.
ProfileName
The name of the profile.
public string ProfileName { get; }
Property Value
ProfilePath
Full path of the profile directory.
public string ProfilePath { get; }
Property Value
Methods
AddBrowserExtensionAsync(string)
Add a browser extension to the current user profile from extensionFolderPath
.
public Task<CoreWebView2BrowserExtension> AddBrowserExtensionAsync(string extensionFolderPath)
Parameters
extensionFolderPath
stringThe manifest.json folder path.
Returns
Remarks
Adds the browser extension using the extension path for unpacked extensions from the local device. Extension is running right after installation.
The extension folder path is the topmost folder of an unpacked browser extension and contains the browser extension manifest file.
If the extensionFolderPath
is an invalid path or doesn't contain the extension manifest.json file, this function will return ERROR_FILE_NOT_FOUND
to callers.
Installed extension will default IsEnabled to true. When AreBrowserExtensionsEnabled is false
, AddBrowserExtension
will fail and return HRESULT ERROR_NOT_SUPPORTED
.
During installation, the content of the extension is not copied to the user data folder. Once the extension is installed, changing the content of the extension will cause the extension to be removed from the installed profile.
When an extension is added the extension is persisted in the corresponding profile. The extension will still be installed the next time you use this profile.
When an extension is installed from a folder path, adding the same extension from the same folder path means reinstalleing this extension. When two extensions with the same Id are installed, only the later installed extension will be kept.
The following summarizes the possible error values that can be returned from AddBrowserExtension
and a description of why these errors occur.
Error value | Description |
---|---|
HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED) | Extensions are disabled. |
HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) | Cannot find manifest.json file or it is not a valid extension manifest. |
E_ACCESSDENIED | Cannot load extension with file or directory name starting with _ , reserved for use by the system. |
E_FAIL | Extension failed to install with other unknown reasons. |
ClearBrowsingDataAsync()
Clear the entirety of the browsing data associated with the profile it is called on. It clears the data regardless of timestamp.
public Task ClearBrowsingDataAsync()
Returns
ClearBrowsingDataAsync(CoreWebView2BrowsingDataKinds)
Clear the browsing data of the associated profile.
public Task ClearBrowsingDataAsync(CoreWebView2BrowsingDataKinds dataKinds)
Parameters
dataKinds
CoreWebView2BrowsingDataKinds
Returns
Examples
Remarks
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();
ClearBrowsingDataAsync(CoreWebView2BrowsingDataKinds, DateTime, DateTime)
Clear the browsing data for the specified dataKinds between the startTime and endTime. Overload the ClearBrowsingDataAsync method to allow for additional time parameters.
public Task ClearBrowsingDataAsync(CoreWebView2BrowsingDataKinds dataKinds, DateTime startTime, DateTime endTime)
Parameters
dataKinds
CoreWebView2BrowsingDataKindsstartTime
DateTimeendTime
DateTime
Returns
Delete()
Delete this profile.
public void Delete()
Remarks
After the API is called, the profile will be marked for deletion. The local profile's directory will be deleted at browser process exit. If it fails to delete, because something else is holding the files open, WebView2 will try to delete the profile at all future browser process starts until successful. The corresponding CoreWebView2s will be closed and the CoreWebView2Profile.Deleted event will be raised. See CoreWebView2Profile.Deleted
for more information. If you try to create a new profile with the same name as an existing profile that has been marked as deleted but hasn't yet been deleted, profile creation will fail with HRESULT_FROM_WIN32(ERROR_DELETE_PENDING).
GetBrowserExtensionsAsync()
Gets a snapshot of the set of extensions on current user profile.
public Task<IReadOnlyList<CoreWebView2BrowserExtension>> GetBrowserExtensionsAsync()
Returns
Remarks
Gets a snapshot of the set of extensions installed at the time GetBrowserExtensions
is called. If an extension is installed or uninstalled after GetBrowserExtensions
completes, the list returned by GetBrowserExtensions
remains the same. When AreBrowserExtensionsEnabled
is false
, GetBrowserExtensions
won't return any extensions on current user profile.
GetNonDefaultPermissionSettingsAsync()
Invokes the handler with a collection of all nondefault permission settings.
public Task<IReadOnlyList<CoreWebView2PermissionSetting>> GetNonDefaultPermissionSettingsAsync()
Returns
Examples
Remarks
Use this method to get the permission state set in the current and previous sessions.
SetPermissionStateAsync(CoreWebView2PermissionKind, string, CoreWebView2PermissionState)
Sets permission state for the given permission kind and origin asynchronously.
public Task SetPermissionStateAsync(CoreWebView2PermissionKind PermissionKind, string origin, CoreWebView2PermissionState State)
Parameters
PermissionKind
CoreWebView2PermissionKindorigin
stringState
CoreWebView2PermissionState
Returns
Remarks
The state change persists across sessions until it is changed by another call to SetPermissionState
, or by setting the State
property in PermissionRequestedEventArgs
. Setting the state to Default will erase any state saved in the profile and restore the default behavior. The origin should have a valid scheme and host (e.g. "https://www.example.com"), otherwise the method fails. Additional URI parts like path and fragment are ignored. For example, "https://wwww.example.com/app1/index.html/" is treated the same as "https://wwww.example.com". See the MDN origin definition for more details.
Events
Deleted
Raised when profile is marked for deletion.
public event EventHandler<object> Deleted
Event Type
Remarks
When this event is raised, the CoreWebView2Profile and its corresponding CoreWebView2s have been closed, and cannot be used anymore.