Skip to content

Commit dd8a88d

Browse files
committed
move plat info into 4 plat articles
1 parent 6add1ef commit dd8a88d

9 files changed

Lines changed: 572 additions & 480 deletions

File tree

microsoft-edge/toc.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,8 +1304,8 @@
13041304

13051305
- name: WinUI 2 (UWP)
13061306
items:
1307-
# - name: WebView2 in WinUI 2 (UWP) apps
1308-
# href: ./webview2/platforms/winui2-uwp.md
1307+
- name: WebView2 in WinUI 2 (UWP) apps
1308+
href: ./webview2/platforms/winui2-uwp.md
13091309

13101310
- name: WinUI 2 (UWP) sample app
13111311
href: ./webview2/samples/webview2_sample_uwp.md
@@ -1317,8 +1317,8 @@
13171317

13181318
- name: WinUI 3 (Windows App SDK)
13191319
items:
1320-
# - name: WebView2 in WinUI 3 (Windows App SDK) apps
1321-
# href: ./webview2/platforms/winui3-windows-app-sdk.md
1320+
- name: WebView2 in WinUI 3 (Windows App SDK) apps
1321+
href: ./webview2/platforms/winui3-windows-app-sdk.md
13221322

13231323
- name: WinUI 3 (Windows App SDK) sample app
13241324
href: ./webview2/samples/webview2-winui3-sample.md
@@ -1328,10 +1328,10 @@
13281328
href: ./webview2/get-started/winui.md
13291329
displayName: WinUI3_GettingStarted # repo dir name
13301330

1331-
- name: WebView2 in WPF apps
1331+
- name: WPF
13321332
items:
1333-
# - name: WebView2 apps on Win32
1334-
# href: ./webview2/platforms/wpf.md
1333+
- name: WebView2 in WPF apps
1334+
href: ./webview2/platforms/wpf.md
13351335

13361336
- name: WPF sample app
13371337
href: ./webview2/samples/webview2wpfbrowser.md
@@ -1360,8 +1360,8 @@
13601360

13611361
- name: HoloLens 2 Unity
13621362
items:
1363-
# - name: WebView2 in HoloLens 2 Unity apps
1364-
# href: ./webview2/platforms/hololens-2-unity.md
1363+
- name: WebView2 in HoloLens 2 Unity apps
1364+
href: ./webview2/platforms/hololens-2-unity.md
13651365

13661366
- name: Get started with WebView2 in HoloLens 2 Unity apps (Preview)
13671367
href: ./webview2/get-started/hololens2.md

microsoft-edge/webview2/concepts/overview-features-apis.md

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,6 @@ when adding an h4 heading, add nav link below the h2
1818
-->
1919

2020

21-
<!-- ====================================================================== -->
22-
## Show WPF elements on top of the WebView2 layer (WebView2CompositionControl) - INCOMING
23-
24-
The `WebView2CompositionControl` prevents the WebView2 control from being the topmost layer in a WPF app and obscuring any WPF elements. `Microsoft.Web.WebView2.Wpf.WebView2CompositionControl` is a drop-in replacement for the standard WPF WebView2 control. Both the WebView2 control and `WebView2CompositionControl` implement the `Microsoft.Web.WebView2.Wpf.IWebView2` interface. Both of them derive from `FrameworkElement`, as follows:
25-
* `FrameworkElement` -> `HwndHost` -> `WebView2`.
26-
* `FrameworkElement` -> `Control` -> `WebView2CompositionControl`.
27-
28-
Background: If you're building a Windows Presentation Foundation (WPF) app and using the WebView2 control, you may find that your app runs into "airspace" issues, where the WebView2 control is always displayed on top, hiding any WPF elements in the same location, even if you try to specify the WPF elements to be above the WebView2 control (using visual tree order or the z-index property, for example).
29-
30-
This issue occurs because the WPF control uses the WPF `HwndHost` to host the Win32 WebView2 control, and `HwndHost` has an issue with airspace.
31-
32-
See also:
33-
* [Mitigating Airspace Issues In WPF Applications](https://dwayneneed.github.io/wpf/2013/02/26/mitigating-airspace-issues-in-wpf-applications.html)
34-
* [PR 4804: WPF Airspace - WebView2CompositionControl](https://github.com/MicrosoftEdge/WebView2Feedback/pull/4804/files?short_path=ebbc3ee#diff-ebbc3ee3560606e2823d68c134ea4aebdc1cb1252aaa9aa2b9a2815e2d8d36b2) - Spec.
35-
36-
##### [.NET/C#](#tab/dotnetcsharp)
37-
38-
* [WebView2CompositionControl Class](/dotnet/api/microsoft.web.webview2.wpf.webview2compositioncontrol)
39-
40-
##### [WinRT/C#](#tab/winrtcsharp)
41-
42-
n/a
43-
44-
##### [Win32/C++](#tab/win32cpp)
45-
46-
n/a
47-
48-
---
49-
50-
5121
<!-- ====================================================================== -->
5222
## Overview of top-level feature areas
5323

microsoft-edge/webview2/get-started/hololens2.md

Lines changed: 0 additions & 188 deletions
Original file line numberDiff line numberDiff line change
@@ -409,194 +409,6 @@ public class WebViewExample : MonoBehaviour, IWithPostMessage
409409
```
410410

411411

412-
<!-- ====================================================================== -->
413-
## Additional considerations for WebView2 on HoloLens 2
414-
415-
416-
<!-- ------------------------------ -->
417-
#### Limitations and known issues
418-
419-
When developing a HoloLens 2 Unity app with WebView2, be aware of some limitations and known issues:
420-
421-
* **Pop-ups**: Pop-ups don't work well within WebView2 inside Unity apps on HoloLens 2, but they work fine in 2D XAML apps on the device. Avoid pop-ups and use alternative techniques or UI designs, such as custom pop-up-like elements within the WebView using HTML, CSS, and JavaScript.
422-
423-
* **New windows**: WebView2 instances on HoloLens 2 navigate within the same window by default, unlike on Desktop. Follow this default behavior for a better user experience. Additionally, the DevTools window cannot be launched.
424-
425-
* **Enterprise authentication**: Automatic Single Sign-On (SSO) leveraging OS-level tokens is currently not supported in WebView2 on HoloLens 2. Users can still sign in by providing credentials, except for cases requiring device-level authentication. Cookie storage works as expected.
426-
427-
* **User interactions**: Unlike native HoloLens 2 slates, WebView2 is best interacted with by using far-interaction hand rays. Touch-to-swipe and scroll interactions might not be supported.
428-
429-
* **Performance**: Complex websites with heavy use of JavaScript or advanced rendering may impact system performance or the host application's framerate. For general performance-related limitations and recommendations, see [Understanding performance for mixed reality](/windows/mixed-reality/develop/advanced-concepts/understanding-performance-for-mixed-reality) in the mixed reality documentation. Also see [Performance optimization](#performance-optimization), below.
430-
431-
432-
<!-- ------------------------------ -->
433-
#### Performance optimization
434-
435-
Optimizing the performance of WebView2 in your HoloLens 2 Unity app is crucial for a smooth user experience. Here are some recommendations:
436-
437-
* **Limit the number of WebView2 instances**: We suggest using only one instance of WebView2 within a Unity app. Reuse the same instance or tear down and create a new one as needed. Keep in mind that removing the WebView prefab from the scene might not destroy the underlying WebView2 instance. You must call the `Destroy()` method on the game object to destroy it properly.
438-
439-
* **Apply general Unity optimization techniques**: To optimize WebView2 performance, use the standard Unity optimization approaches, such as occlusion culling or limiting the update rate. For more information, see [Performance recommendations for Unity](/windows/mixed-reality/develop/unity/performance-recommendations-for-unity?tabs=openxr) in the mixed reality documentation.
440-
441-
* **Profile and monitor WebView2 performance**: There are several ways to profile the performance of a HoloLens 2 Unity application:
442-
443-
* **Unity Profiler**: A built-in tool in Unity that allows you to measure and optimize the performance of your application on various platforms, including HoloLens 2.
444-
445-
* **Visual Profiler**: A feature of the Mixed Reality Toolkit that provides an in-application view of your application's performance.
446-
447-
* **PIX**: A performance tuning and debugging tool for Windows that can also be used to profile Unity applications on HoloLens 2.
448-
449-
450-
<!-- ------------------------------ -->
451-
#### Navigation
452-
453-
In [Step 7 - Extending WebView2 functionality](#step-7---extending-webview2-functionality), we touched on some navigation methods. In this section, we'll expand on what we learned.
454-
455-
See also:
456-
* [WebView2 API Reference](../webview2-api-reference.md)
457-
* [API Reference for Mixed Reality WebView plugin](/windows/mixed-reality/develop/advanced-concepts/webview2-unity-plugin) - for HoloLens 2 in the WebView2 Unity plugin.
458-
<!-- dest. TOC title:
459-
WebView2 Unity Plugin API -->
460-
461-
462-
<!-- ---------- -->
463-
###### IWebView interface
464-
465-
<!-- [IWebView::Load method]()-->
466-
467-
The `IWebView` interface exposes a few methods, events, and properties related to page navigation. The main functionality exposed here is the ability to navigate to a given URL, by using `Load(Uri url)`:
468-
469-
```C#
470-
public interface IWebView
471-
{
472-
// Non-navigation methods are removed for clarity.
473-
474-
event WebView_OnNavigated Navigated;
475-
476-
Uri Page { get; }
477-
478-
void Load(Uri url);
479-
480-
void Reload(bool ignoreCache);
481-
}
482-
```
483-
484-
485-
<!-- ---------- -->
486-
###### IWithBrowserHistory interface
487-
488-
The `IWithBrowserHistory` interface exposes a few methods and events related to page navigation. This mainly allows developers to navigate forward and backward, as you would expect with a typical web-browsing experience:
489-
490-
```C#
491-
public interface IWithBrowserHistory : IWebView
492-
{
493-
// Non-navigation methods are removed for clarity.
494-
495-
event WebView_OnCanGoForwardUpdated CanGoForwardUpdated;
496-
497-
event WebView_OnCanGoBackUpdated CanGoBackUpdated;
498-
499-
void GoBack();
500-
501-
void GoForward();
502-
}
503-
```
504-
505-
506-
<!-- ---------- -->
507-
###### SetVirtualHostNameToFolderMapping and SetVirtualHostMapping
508-
509-
The [CoreWebView2.SetVirtualHostNameToFolderMapping Method](/dotnet/api/microsoft.web.webview2.core.corewebview2.setvirtualhostnametofoldermapping) enables mapping between a virtual host name and a folder path, making it accessible to websites using that host name. This method maps a local domain name to a local folder, so that the WebView2 control loads content from the specified local folder when attempting to access a resource for that domain.
510-
511-
The WebView plugin for Unity exposes this functionality through the `IWithVirtualHost` interface, which has a single method, `SetVirtualHostMapping(string hostName, string folderPath)`:
512-
513-
```C#
514-
public interface IWithVirtualHost : IWebView
515-
{
516-
void SetVirtualHostMapping(string hostName, string folderPath);
517-
}
518-
```
519-
520-
To use the `SetVirtualHostMapping` method, set `hostName` to any valid URL conforming string, such as `webview2.sample`. `folderPath` can be an absolute path or a path relative to the application's working directory, such as `Assets\Html`.
521-
522-
Assuming we have an HTML file called `demo.html` under `Assets\Html`, the following code snippet demonstrates loading `demo.html` by using the WebView plugin for Unity:
523-
524-
```C#
525-
using Microsoft.MixedReality.WebView;
526-
527-
public class WebViewExample : MonoBehaviour
528-
{
529-
private void Start()
530-
{
531-
var webViewComponent = gameObject.GetComponent<WebView>();
532-
533-
webViewComponent.GetWebViewWhenReady((IWebView webView) =>
534-
{
535-
((IWithVirtualHost)webView).SetVirtualHostMapping("webview2.sample", "Assets\\Html");
536-
537-
// Navigate to our local content.
538-
webViewComponent.Load(new Uri("http://webview2.sample/demo.html"));
539-
});
540-
}
541-
}
542-
```
543-
544-
545-
<!-- ------------------------------ -->
546-
#### Input
547-
548-
There are various ways to handle input in Unity for mixed reality applications.
549-
550-
* [Input overview — MRTK2](/windows/mixed-reality/mrtk-unity/mrtk2/features/input/overview) - recommended for Mixed Reality Toolkit 2.8 applications.
551-
* [Input — MRTK3](/windows/mixed-reality/mrtk-unity/mrtk3-input/packages/input/overview) - recommended for Mixed Reality Toolkit 3 applications.
552-
* [Unity Input System](https://docs.unity3d.com/Packages/com.unity.inputsystem@1.5/manual/index.html)
553-
554-
Regardless of the input system used within your Unity application, interop code between the various application input events and the WebView plugin for Unity is required. This means translating those events (such as Pointer events) into a `WebViewMouseEventData` object and then forwarding those events to the plugin via the `IWithMouseEvent` interface:
555-
556-
```C#
557-
public interface IWithMouseEvents : IWithInputEvents
558-
{
559-
void MouseEvent(WebViewMouseEventData mouseEvent);
560-
}
561-
```
562-
563-
WebView2 is unaware of Unity's input system and likely has a different coordinate system than your Unity scene. As a result, when there is a pointer-down event, its coordinates must be translated into the coordinate system of the WebView2 control. Additionally, the pointer-down event needs to be converted into an appropriate `WebViewMouseEventData` event type.
564-
565-
Simple example:
566-
567-
```C#
568-
using Microsoft.MixedReality.WebView;
569-
570-
public class WebViewExample : MonoBehaviour, IPointerDownHandler
571-
{
572-
// WebView setup steps skipped for brevity
573-
574-
public void OnPointerDown(PointerEventData eventData)
575-
{
576-
IWithMouseEvents mouseEventsWebView = webView as IWithMouseEvents;
577-
578-
// Call hypothetical function which converts the event's x, y into the WebView2's coordinate space.
579-
var hitCoord = ConvertToWebViewSpace(eventData.position.x, eventData.position.y);
580-
581-
WebViewMouseEventData mouseEvent = new WebViewMouseEventData
582-
{
583-
X = hitCoord.x,
584-
Y = hitCoord.y,
585-
Type = WebViewMouseEventData.EventType.MouseDown,
586-
Button = WebViewMouseEventData.MouseButton.ButtonLeft,
587-
TertiaryAxisDeviceType = WebViewMouseEventData.TertiaryAxisDevice.PointingDevice
588-
};
589-
590-
// Propagate the event to the WebView plugin.
591-
mouseEventsWebView.MouseEvent(mouseEvent);
592-
}
593-
}
594-
```
595-
596-
In the above example, pointer-down events are converted into `WebViewMouseEventData` objects and forwarded to the WebView plugin for Unity. It is essentially converted into a mouse-down event. In order to create mouse click events, pointer-up events would need to be handled in a similar fashion.
597-
598-
In the example above, `ConvertToWebViewSpace` is intentionally not implemented.
599-
600412

601413
<!-- ====================================================================== -->
602414
## See also

microsoft-edge/webview2/get-started/winui.md

Lines changed: 1 addition & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -512,89 +512,9 @@ To display an alert when the user tries to navigate to a non-HTTPS site:
512512
Congratulations, you've built a WebView2 WinUI 3 (Windows App SDK) app!
513513

514514

515-
<!-- ====================================================================== -->
516-
## WinAppSDK supports custom WebView2 environments
517-
518-
WinAppSDK supports custom WebView2 environments, starting with WinAppSDK 1.5 ([1.5.0-experimental2](/windows/apps/windows-app-sdk/experimental-channel#version-15-experimental-150-experimental2)). For more information, see [WinUI3 WebView2 with a custom CoreWebView2Environment](https://github.com/microsoft/microsoft-ui-xaml/issues/6150).
519-
520-
To instantiate a custom WebView2 environment, you could initialize WebView2 with one of the overrides of `WebView2.EnsureCoreWebView2Async` (listed below), and pass in your custom `CoreWebView2Environment` (and, optionally, custom `CoreWebView2ControllerOptions`):
521-
522-
```csharp
523-
public IAsyncAction EnsureCoreWebView2Async (CoreWebView2Environment environment)
524-
public IAsyncAction EnsureCoreWebView2Async (CoreWebView2Environment environment, CoreWebView2ControllerOptions controllerOptions)
525-
```
526-
527-
Also see the example code in [Disabling SmartScreen navigation](#disabling-smartscreen-navigation), below.
528-
529-
API Reference:
530-
* [WebView2.EnsureCoreWebView2Async](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.webview2.ensurecorewebview2async)
531-
* [CoreWebView2ControllerOptions](/microsoft-edge/webview2/reference/winrt/microsoft_web_webview2_core/corewebview2controlleroptions)
532-
* [CoreWebView2Environment](/microsoft-edge/webview2/reference/winrt/microsoft_web_webview2_core/corewebview2environment)
533-
* [CoreWebView2EnvironmentOptions](/microsoft-edge/webview2/reference/winrt/microsoft_web_webview2_core/corewebview2environmentoptions)
534-
535-
536-
<!-- ====================================================================== -->
537-
## WinUI 3 WebView2 special considerations
538-
539-
540-
<!-- ------------------------------ -->
541-
#### Disabling SmartScreen navigation
542-
543-
WebView2 sends URLs that are navigated to in your application to the [SmartScreen](/windows/security/threat-protection/microsoft-defender-smartscreen/microsoft-defender-smartscreen-overview) service, to ensure that your customers stay secure. If you want to disable this navigation, use a custom `CoreWebView2Environment`, as follows:
544-
545-
```csharp
546-
CoreWebView2EnvironmentOptions environmentOptions = new CoreWebView2EnvironmentOptions();
547-
environmentOptions.AdditionalBrowserArguments = "--disable-features=msSmartScreenProtection";
548-
549-
string browserFolder = null; // Use null to get default browser folder
550-
string userDataFolder = null; // Use null to get default user data folder
551-
CoreWebView2Environment environment = await CoreWebView2Environment.CreateWithOptionsAsync(
552-
browserFolder, userDataFolder, environmentOptions);
553-
554-
// ...
555-
556-
this.WebView2.EnsureCoreWebView2Async(environment);
557-
```
558-
559-
560-
<!-- ---------- -->
561-
###### Disabling SmartScreen by using an environment variable
562-
563-
We no longer recommend using an environment variable. Use the above API code-based approach instead.
564-
565-
* `Environment.SetEnvironmentVariable("WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS", "--disable-features=msSmartScreenProtection");`
566-
567-
This environment variable must be set prior to `CoreWebView2` creation, which occurs when the [WebView2.Source property](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.webview2.source#microsoft-ui-xaml-controls-webview2-source) is initially set or the [WebView2.EnsureCoreWebView2Async method](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.webview2.ensurecorewebview2async#microsoft-ui-xaml-controls-webview2-ensurecorewebview2async) is initially called.
568-
569-
570-
<!-- ------------------------------ -->
571-
#### Setting DefaultBackgroundColor
572-
573-
In WebView2 for WinUI 3, the `DefaultBackgroundColor` setting exists on the WebView2 XAML object. For example:
574-
575-
```csharp
576-
public MainWindow()
577-
{
578-
this.InitializeComponent();
579-
MyWebView.DefaultBackgroundColor = Colors.LightBlue;
580-
}
581-
```
582-
583-
584-
<!-- ------------------------------ -->
585-
#### Transparency
586-
587-
WinUI 3 doesn't support transparent backgrounds. See [Transparent background support for WebView2? · Issue #2992](https://github.com/microsoft/microsoft-ui-xaml/issues/2992).
588-
589-
590-
<!-- ------------------------------ -->
591-
#### WinAppSDK support for custom WebView2 environments
592-
593-
See [WinAppSDK supports custom WebView2 environments](#winappsdk-supports-custom-webview2-environments), above.
594-
595-
596515
<!-- ====================================================================== -->
597516
## See also
517+
<!-- todo: all links in article -->
598518

599519
* [WebView2 API Reference](../webview2-api-reference.md)
600520
* [Introduction to Microsoft Edge WebView2](../index.md) - overview of features.

0 commit comments

Comments
 (0)