WebView2 in WinUI 2 (UWP) apps
The following considerations apply to WebView2 in WinUI 2 (UWP) apps. The WebView2 WinUI 2 (UWP) control is in development.
Autofill UI
Autofill UI is not implemented yet for WebView2 for UWP apps.
See also:
- Autofill in Overview of WebView2 APIs.
Print to PDF
Print to PDF requires that the app have access to a writeable location in UWP, such as a local folder. For a full list of UWP-accessible paths, see File access permissions.
See also:
- Printing in Overview of WebView2 APIs.
Default printing
Default printing is disabled for WebView2 for UWP apps. However, you can capture and print the current viewport, by calling CapturePreview
.
See also:
- Image capture in Overview of WebView2 APIs.
SmartScreen
WebView2 sends URLs that are navigated to in your application to the SmartScreen service, to ensure that your customers stay secure. If you want to disable this navigation, you can do so via an environment variable:
Environment.SetEnvironmentVariable("WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS", "--disable-features=msSmartScreenProtection");
This environment variable must be set prior to CoreWebView2
creation, which occurs when the WebView2.Source property is initially set or the WebView2.EnsureCoreWebView2Async method is initially called.
Downloading files
There are a couple of known limitations for current downloads behavior for WebView2 in UWP.
Save As
Saving files via Save As is working and is enabled for WebView2 for UWP apps. The files will be saved in the folder that the user selects.
Which folder the files are downloaded to
If the host doesn't change the ResultFilePath
of the downloaded file, the downloaded files will be downloaded to a subfolder with the app package's name in the Downloads
folder.
If the host changes the ResultFilePath
of the downloaded file, the file will only be downloaded if the app has access to that file path by default. If you want to use a file location that the app doesn't have access to by default, you must set the corresponding capability. See App capability declarations in the UWP documentation.
Downloads Hub
Opening files and folders from the Downloads Hub is disabled. Clicking on the file or folder icon won't open the respective file/folder.
See also:
- Downloads in Overview of WebView2 APIs.
XAML limitation
XAML Island support requires additional work and may be considered for future releases.
Setting DefaultBackgroundColor
On WinUI 2, the DefaultBackgroundColor
property is not exposed directly. You can set the default background color by setting an environment variable, as follows:
Environment.SetEnvironmentVariable("WEBVIEW2_DEFAULT_BACKGROUND_COLOR", "FF000000");
See also:
- .NET: WebView2.DefaultBackgroundColor Property
- Win32: ICoreWebView2Controller2::DefaultBackgroundColor property (get, put)
Setting transparency
On WinUI 2, transparency is achieved by setting the color to 00FFFFFF
.
CSS cursors
On WinUI 2 (UWP), CSS cursors have the following limitations.
Image URLs
The CSS cursor cannot be an image URL, such as cursor: url(https://contoso.com/cursor.png), pointer;
. See CSS - cursor loaded from URL doesn't work.
Predefined CSS cursors
On WinUI 2 (UWP), some of the predefined CSS cursors are not supported. You can use CSS cursors to change the cursor to some of the predefined cursors, such as cursor: wait;
or cursor: crosshair;
, but not to others, such as cursor: progress
or cursor: none
.
Keyword | Supported? |
---|---|
General | |
auto | ✔️ |
default | ✔️ |
none | ❌ |
Links & status | |
context-menu | ✔️ |
help | ✔️ |
pointer | ✔️ |
progress | ❌ |
wait | ✔️ |
Selection | |
cell | ❌ |
crosshair | ✔️ |
text | ✔️ |
vertical-text | ❌ |
Drag & drop | |
alias | ❌ |
copy | ❌ |
move | ✔️ |
no-drop | ✔️ |
not-allowed | ✔️ |
grab | ❌ |
grabbing | ❌ |
Resizing & scrolling | |
all-scroll | ✔️ |
col-resize | ❌ |
row-resize | ❌ |
n-resize | ✔️ |
e-resize | ✔️ |
s-resize | ✔️ |
w-resize | ✔️ |
ne-resize | ✔️ |
nw-resize | ✔️ |
se-resize | ✔️ |
sw-resize | ✔️ |
ew-resize | ✔️ |
ns-resize | ✔️ |
nesw-resize | ✔️ |
nwse-resize | ✔️ |
Zooming | |
zoom-in | ❌ |
zoom-out | ❌ |
See also:
- CSS cursors - the Values section describes the above keyword values.
Microsoft Edge Developer Tools
On WinUI 2, Microsoft Edge DevTools cannot be launched inside a store-signed WebView2 WinUI 2 (UWP) app. However, you can work around this by using remote debugging. See Remote debugging WebView2 WinUI 2 (UWP) apps.
API limitations
The following classes aren't accessible in WinUI 2:
CoreWebView2EnvironmentOptions
CoreWebView2ControllerOptions
See also
- Autofill in Overview of WebView2 APIs.
- Printing in Overview of WebView2 APIs.
- Image capture in Overview of WebView2 APIs.
- Downloads in Overview of WebView2 APIs.
- Remote debugging WebView2 WinUI 2 (UWP) apps
API Reference:
- .NET: WebView2.DefaultBackgroundColor Property
- Win32: ICoreWebView2Controller2::_getDefaultBackgroundColor
- Win32: ICoreWebView2Controller2::_putDefaultBackgroundColor
Windows docs:
- SmartScreen
- WebView2.Source property
- WebView2.EnsureCoreWebView2Async method
- App capability declarations
MDN:
- Values in cursor CSS property at MDN.
WebView2Feedback repo: