Skip to content

Commit 46de9bc

Browse files
Copilotjfversluis
andauthored
Document WebView2/BlazorWebView/HybridWebView issues with Program Files installation (#3035)
* Initial plan * Add Windows Program Files warning for WebView2/BlazorWebView/HybridWebView Co-authored-by: jfversluis <939291+jfversluis@users.noreply.github.com> * Extract WebView2 Program Files warning into reusable include snippet Co-authored-by: jfversluis <939291+jfversluis@users.noreply.github.com> * Fix markdown linting errors in webview2-program-files-warning.md Co-authored-by: jfversluis <939291+jfversluis@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jfversluis <939291+jfversluis@users.noreply.github.com> Co-authored-by: Gerald Versluis <gerald.versluis@microsoft.com>
1 parent 1d3656c commit 46de9bc

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

docs/user-interface/controls/blazorwebview.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Host a Blazor web app in a .NET MAUI app using BlazorWebView"
33
description: "The .NET MAUI BlazorWebView control enables you to host a Blazor web app in your .NET MAUI app, and integrate the app with device features."
4-
ms.date: 05/13/2025
4+
ms.date: 09/19/2025
55
---
66

77
# Host a Blazor web app in a .NET MAUI app using BlazorWebView
@@ -33,6 +33,8 @@ Browser developer tools can be used to inspect .NET MAUI Blazor apps. For more i
3333
> [!NOTE]
3434
> While Visual Studio installs all the required tooling to develop .NET MAUI Blazor apps, end users of .NET MAUI Blazor apps on Windows must install the [WebView2](https://developer.microsoft.com/microsoft-edge/webview2/) runtime.
3535
36+
[!INCLUDE [WebView2 Program Files warning](includes/webview2-program-files-warning.md)]
37+
3638
For more information about Blazor Hybrid apps, see [ASP.NET Core Blazor Hybrid](/aspnet/core/blazor/hybrid).
3739

3840
[!INCLUDE [browser-engines](includes/browser-engines.md)]

docs/user-interface/controls/hybridwebview.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: HybridWebView
33
description: Learn how to use a HybridWebView to host HTML/JS/CSS content in a WebView, and communicate between that content and .NET.
44
ms.topic: concept-article
5-
ms.date: 08/20/2025
5+
ms.date: 09/19/2025
66
monikerRange: ">=net-maui-9.0"
77

88
#customer intent: As a developer, I want to host HTML/JS/CSS content in a web view so that I can publish the web app as a mobile app.
@@ -34,6 +34,8 @@ The entire app, including the web content, is packaged and runs locally on a dev
3434
> [!IMPORTANT]
3535
> By default, the <xref:Microsoft.Maui.Controls.HybridWebView> control won't be available when full trimming or Native AOT is enabled. To change this behavior, see [Trimming feature switches](~/deployment/trimming.md#trimming-feature-switches).
3636
37+
[!INCLUDE [WebView2 Program Files warning](includes/webview2-program-files-warning.md)]
38+
3739
[!INCLUDE [browser-engines](includes/browser-engines.md)]
3840

3941
## Create a .NET MAUI HybridWebView app
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
ms.topic: include
3+
ms.date: 09/19/2025
4+
---
5+
6+
> [!WARNING]
7+
> On Windows, apps using WebView2-based controls that are installed to the `Program Files` directory may fail to render content properly. This occurs because WebView2 attempts to write its cache and user data files to the app's installation directory, which has restricted write permissions in `Program Files`. To resolve this issue, set the `WEBVIEW2_USER_DATA_FOLDER` environment variable before any WebView control is initialized:
8+
>
9+
> ```csharp
10+
> #if WINDOWS
11+
> var userDataFolder = Path.Combine(FileSystem.AppDataDirectory, "WebView2");
12+
> Environment.SetEnvironmentVariable("WEBVIEW2_USER_DATA_FOLDER", userDataFolder);
13+
> #endif
14+
> ```
15+
>
16+
> Place this code in your `App.xaml.cs` constructor or in `Platforms\Windows\App.xaml.cs` before any WebView control is created. This directs WebView2 to use a writable location in the user's AppData directory instead of the restricted Program Files location.

docs/user-interface/controls/webview.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "WebView"
33
description: "This article explains how to use the .NET MAUI WebView to display remote web pages, local HTML files, and HTML strings."
4-
ms.date: 08/19/2025
4+
ms.date: 09/19/2025
55
zone_pivot_groups: devices-platforms
66
---
77

@@ -40,6 +40,8 @@ The `Source` property can be set to an `UrlWebViewSource` object or a `HtmlWebVi
4040
> [!IMPORTANT]
4141
> A <xref:Microsoft.Maui.Controls.WebView> must specify its <xref:Microsoft.Maui.Controls.VisualElement.HeightRequest> and <xref:Microsoft.Maui.Controls.VisualElement.WidthRequest> properties when contained in a <xref:Microsoft.Maui.Controls.HorizontalStackLayout>, <xref:Microsoft.Maui.Controls.StackLayout>, or <xref:Microsoft.Maui.Controls.VerticalStackLayout>. If you fail to specify these properties, the <xref:Microsoft.Maui.Controls.WebView> will not render.
4242
43+
[!INCLUDE [WebView2 Program Files warning](includes/webview2-program-files-warning.md)]
44+
4345
[!INCLUDE [browser-engines](includes/browser-engines.md)]
4446

4547
## Display a web page

0 commit comments

Comments
 (0)