Used to manage profile options that created by CoreWebView2Environment.CreateCoreWebView2ControllerOptions.
Summary
Members | Description |
---|---|
DefaultBackgroundColor | Gets or sets the WebView2 default background color early during initialization. |
IsInPrivateModeEnabled | Manage the controller's InPrivate mode. |
ProfileName | Manage the name of the controller's profile. |
ScriptLocale | Manages the value of the controller's script locale. |
Properties
DefaultBackgroundColor
Color DefaultBackgroundColor
Gets or sets the WebView2 default background color early during initialization.
This API allows users to initialize the DefaultBackgroundColor
early, preventing a white flash that can occur while WebView2 is loading when the background color is set to something other than white. With early initialization, the color remains consistent from the start. After initialization, it will return the set value.
The DefaultBackgroundColor
is the color that renders underneath all web content. This means WebView2 renders this color when there is no web content loaded. When no background color is defined in WebView2, it uses the DefaultBackgroundColor
property to render the background.By default, this color is set to white. This API only supports opaque colors and full transparency. It will fail for colors with alpha values that don't equal 0 or 255. When WebView2 is set to be fully transparent, it does not render a background, allowing the content from windows behind it to be visible.
IsInPrivateModeEnabled
bool IsInPrivateModeEnabled
Manage the controller's InPrivate mode.
ProfileName
string ProfileName
Manage the name of the controller's profile.
The ProfileName
property is to specify a profile name, which is only allowed to contain the following ASCII characters. It has a maximum length of 64 characters excluding the null-terminator. It is ASCII case insensitive.
- alphabet characters: a-z and A-Z
- digit characters: 0-9
- and '#', '', '', '(', ')', '+', '-', '_', '~', '.', ' ' (space).
Note: the text must not end with a period '.' or ' ' (space). And, although upper-case letters are allowed, they're treated just as lower-case counterparts because the profile name will be mapped to the real profile directory path on disk and Windows file system handles path names in a case-insensitive way.
ScriptLocale
string ScriptLocale
Manages the value of the controller's script locale.
The ScriptLocale
property is to specify the default script locale. It sets the default locale for all Intl JavaScript APIs and other JavaScript APIs that depend on it, namely Intl.DateTimeFormat()
which affects string formatting like in the time/date formats.The intended locale value is in the format of BCP 47 Language Tags. More information can be found from IETF BCP47.
The default value for ScriptLocale will be depend on the WebView2 language and OS region. If the language portions of the WebView2 language and OS region match, then it will use the OS region. Otherwise, it will use the WebView2 language.
OS Region | WebView2 Language | Default WebView2 ScriptLocale |
---|---|---|
en-GB | en-US | en-GB |
es-MX | en-US | en-US |
en-US | en-GB | en-US |
You can set the ScriptLocale to the empty string to get the default ScriptLocale value. Use OS specific APIs to determine the OS region to use with this property if you always want to match with the OS region. For example:
CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture;
return cultureInfo.Name