Skip to content

Commit

Permalink
Merge pull request #3340 from MicrosoftDocs/user/mikehoffms/overview-…
Browse files Browse the repository at this point in the history
…apis-jan-2025

Move platform info from GetStart tut to general platform page
  • Loading branch information
captainbrosset authored Feb 4, 2025
2 parents 609c577 + 6994c69 commit 1290722
Show file tree
Hide file tree
Showing 18 changed files with 729 additions and 493 deletions.
72 changes: 36 additions & 36 deletions microsoft-edge/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1283,8 +1283,12 @@
items:
- name: Win32
items:
# - name: WebView2 in Win32 apps
# href: ./webview2/platforms/win32.md
- name: WebView2 in Win32 apps
href: ./webview2/platforms/win32.md

- name: Get started with WebView2 in Win32 apps
href: ./webview2/get-started/win32.md
displayName: Win32_GettingStarted # repo dir name

- name: Win32 sample app
href: ./webview2/samples/webview2apissample.md
Expand All @@ -1298,40 +1302,40 @@
href: ./webview2/samples/webview2browser.md
displayName: WebView2Browser # repo dir name

- name: Get started with WebView2 in Win32 apps
href: ./webview2/get-started/win32.md
displayName: Win32_GettingStarted # repo dir name

- name: WinUI 2 (UWP)
items:
# - name: WebView2 in WinUI 2 (UWP) apps
# href: ./webview2/platforms/winui2-uwp.md

- name: WinUI 2 (UWP) sample app
href: ./webview2/samples/webview2_sample_uwp.md
displayName: webview2_sample_uwp # repo dir name
- name: WebView2 in WinUI 2 (UWP) apps
href: ./webview2/platforms/winui2-uwp.md

- name: Get started with WebView2 in WinUI 2 (UWP) apps
href: ./webview2/get-started/winui2.md
displayName: WinUI2_GettingStarted # repo dir name

- name: WinUI 2 (UWP) sample app
href: ./webview2/samples/webview2_sample_uwp.md
displayName: webview2_sample_uwp # repo dir name

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

- name: WinUI 3 (Windows App SDK) sample app
href: ./webview2/samples/webview2-winui3-sample.md
displayName: WebView2_WinUI3_Sample # repo dir name
- name: WebView2 in WinUI 3 (Windows App SDK) apps
href: ./webview2/platforms/winui3-windows-app-sdk.md

- name: Get started with WebView2 in WinUI 3 (Windows App SDK) apps
href: ./webview2/get-started/winui.md
displayName: WinUI3_GettingStarted # repo dir name

- name: WebView2 in WPF apps
- name: WinUI 3 (Windows App SDK) sample app
href: ./webview2/samples/webview2-winui3-sample.md
displayName: WebView2_WinUI3_Sample # repo dir name

- name: WPF
items:
# - name: WebView2 apps on Win32
# href: ./webview2/platforms/wpf.md
- name: WebView2 in WPF apps
href: ./webview2/platforms/wpf.md

- name: Get started with WebView2 in WPF apps
href: ./webview2/get-started/wpf.md
displayName: WPF_GettingStarted # repo dir name

- name: WPF sample app
href: ./webview2/samples/webview2wpfbrowser.md
Expand All @@ -1341,39 +1345,35 @@
href: ./webview2/samples/wv2cdpextensionwpfsample.md
displayName: WV2CDPExtensionWPFSample # repo dir name

- name: Get started with WebView2 in WPF apps
href: ./webview2/get-started/wpf.md
displayName: WPF_GettingStarted # repo dir name

- name: WinForms
items:
# - name: WebView2 in WinForms apps
# href: ./webview2/platforms/winforms.md

- name: WinForms sample app
href: ./webview2/samples/webview2windowsformsbrowser.md
displayName: WebView2WindowsFormsBrowser # repo dir name
- name: WebView2 in WinForms apps
href: ./webview2/platforms/winforms.md

- name: Get started with WebView2 in WinForms apps
href: ./webview2/get-started/winforms.md
displayName: WinForms_GettingStarted # repo dir name

- name: WinForms sample app
href: ./webview2/samples/webview2windowsformsbrowser.md
displayName: WebView2WindowsFormsBrowser # repo dir name

- name: HoloLens 2 Unity
items:
# - name: WebView2 in HoloLens 2 Unity apps
# href: ./webview2/platforms/hololens-2-unity.md
- name: WebView2 in HoloLens 2 Unity apps
href: ./webview2/platforms/hololens-2-unity.md

- name: Get started with WebView2 in HoloLens 2 Unity apps (Preview)
href: ./webview2/get-started/hololens2.md
displayName: HoloLens2_GettingStarted # repo dir name

- name: WebView2 sample apps
href: ./webview2/code-samples-links.md # delete & redir?

- name: Getting Started tutorials
href: ./webview2/get-started/get-started.md # delete & redir?
displayName: GettingStartedGuides # repo dir name

- name: WebView2 sample apps
href: ./webview2/code-samples-links.md # delete & redir?

# -----------------------------------------------------------------------------
- name: Navigation, events, and authentication
items:
Expand Down
1 change: 1 addition & 0 deletions microsoft-edge/webview2/concepts/overview-features-apis.md
Original file line number Diff line number Diff line change
Expand Up @@ -2986,6 +2986,7 @@ Use the following APIs to forward `IDropTarget` events from the system to the We

---


<!-- ------------------------------ -->
#### Accessibility

Expand Down
3 changes: 2 additions & 1 deletion microsoft-edge/webview2/get-started/get-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ ms.date: 02/22/2023
---
# Getting Started tutorials

These articles cover how to set up your development tools and create an initial WebView2 app, like a Hello World app with basic functionality. Learn about WebView2 concepts along the way.
These articles cover how to set up your development tools and create an initial WebView2 app, like a Hello World app with basic functionality. You learn WebView2 concepts along the way. If you want to run a sample first, see [Win32 sample app](../samples/webview2apissample.md) or another sample app article.


| Article | Completed project | Description |
|---|---|---|
Expand Down
191 changes: 2 additions & 189 deletions microsoft-edge/webview2/get-started/hololens2.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ ms.date: 11/25/2024

This tutorial is for developers using WebView2 in immersive HoloLens 2 Unity applications.

This article is to learn to write your own WebView2 code. If you want to run a sample first, see [Win32 sample app](../samples/webview2apissample.md) or another sample app article.

> [!IMPORTANT]
> WebView2 on Hololens 2 continues to be available. However, support for WebView2 on Hololens 2 is discontinued; there are no planned bug fixes or content updates, and technical support has ended. Applications that use WebView2 on Hololens 2 are not guaranteed to continue to work.
Expand Down Expand Up @@ -409,195 +411,6 @@ public class WebViewExample : MonoBehaviour, IWithPostMessage
```


<!-- ====================================================================== -->
## Additional considerations for WebView2 on HoloLens 2


<!-- ------------------------------ -->
#### Limitations and known issues

When developing a HoloLens 2 Unity app with WebView2, be aware of some limitations and known issues:

* **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.

* **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.

* **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.

* **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.

* **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.


<!-- ------------------------------ -->
#### Performance optimization

Optimizing the performance of WebView2 in your HoloLens 2 Unity app is crucial for a smooth user experience. Here are some recommendations:

* **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.

* **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.

* **Profile and monitor WebView2 performance**: There are several ways to profile the performance of a HoloLens 2 Unity application:

* **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.

* **Visual Profiler**: A feature of the Mixed Reality Toolkit that provides an in-application view of your application's performance.

* **PIX**: A performance tuning and debugging tool for Windows that can also be used to profile Unity applications on HoloLens 2.


<!-- ------------------------------ -->
#### Navigation

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.

See also:
* [WebView2 API Reference](../webview2-api-reference.md)
* [API Reference for Mixed Reality WebView plugin](/windows/mixed-reality/develop/advanced-concepts/webview2-unity-plugin) - for HoloLens 2 in the WebView2 Unity plugin.
<!-- dest. TOC title:
WebView2 Unity Plugin API -->


<!-- ---------- -->
###### IWebView interface

<!-- [IWebView::Load method]()-->

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)`:

```C#
public interface IWebView
{
// Non-navigation methods are removed for clarity.
event WebView_OnNavigated Navigated;

Uri Page { get; }

void Load(Uri url);

void Reload(bool ignoreCache);
}
```


<!-- ---------- -->
###### IWithBrowserHistory interface

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:

```C#
public interface IWithBrowserHistory : IWebView
{
// Non-navigation methods are removed for clarity.
event WebView_OnCanGoForwardUpdated CanGoForwardUpdated;

event WebView_OnCanGoBackUpdated CanGoBackUpdated;

void GoBack();

void GoForward();
}
```


<!-- ---------- -->
###### SetVirtualHostNameToFolderMapping and SetVirtualHostMapping

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.

The WebView plugin for Unity exposes this functionality through the `IWithVirtualHost` interface, which has a single method, `SetVirtualHostMapping(string hostName, string folderPath)`:

```C#
public interface IWithVirtualHost : IWebView
{
void SetVirtualHostMapping(string hostName, string folderPath);
}
```

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`.

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:

```C#
using Microsoft.MixedReality.WebView;

public class WebViewExample : MonoBehaviour
{
private void Start()
{
var webViewComponent = gameObject.GetComponent<WebView>();

webViewComponent.GetWebViewWhenReady((IWebView webView) =>
{
((IWithVirtualHost)webView).SetVirtualHostMapping("webview2.sample", "Assets\\Html");

// Navigate to our local content.
webViewComponent.Load(new Uri("http://webview2.sample/demo.html"));
});
}
}
```


<!-- ------------------------------ -->
#### Input

There are various ways to handle input in Unity for mixed reality applications.

* [Input overview — MRTK2](/windows/mixed-reality/mrtk-unity/mrtk2/features/input/overview) - recommended for Mixed Reality Toolkit 2.8 applications.
* [Input — MRTK3](/windows/mixed-reality/mrtk-unity/mrtk3-input/packages/input/overview) - recommended for Mixed Reality Toolkit 3 applications.
* [Unity Input System](https://docs.unity3d.com/Packages/[email protected]/manual/index.html)

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:

```C#
public interface IWithMouseEvents : IWithInputEvents
{
void MouseEvent(WebViewMouseEventData mouseEvent);
}
```

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.

Simple example:

```C#
using Microsoft.MixedReality.WebView;

public class WebViewExample : MonoBehaviour, IPointerDownHandler
{
// WebView setup steps skipped for brevity
public void OnPointerDown(PointerEventData eventData)
{
IWithMouseEvents mouseEventsWebView = webView as IWithMouseEvents;

// Call hypothetical function which converts the event's x, y into the WebView2's coordinate space.
var hitCoord = ConvertToWebViewSpace(eventData.position.x, eventData.position.y);

WebViewMouseEventData mouseEvent = new WebViewMouseEventData
{
X = hitCoord.x,
Y = hitCoord.y,
Type = WebViewMouseEventData.EventType.MouseDown,
Button = WebViewMouseEventData.MouseButton.ButtonLeft,
TertiaryAxisDeviceType = WebViewMouseEventData.TertiaryAxisDevice.PointingDevice
};

// Propagate the event to the WebView plugin.
mouseEventsWebView.MouseEvent(mouseEvent);
}
}
```

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.

In the example above, `ConvertToWebViewSpace` is intentionally not implemented.


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

Expand Down
2 changes: 2 additions & 0 deletions microsoft-edge/webview2/get-started/win32.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ ms.date: 07/29/2022

<!-- TODO: Rewrite to start from a project template? -->

This article is to learn to write your own WebView2 code. If you want to run a sample first, see [Win32 sample app](../samples/webview2apissample.md) or another sample app article.

In this article, you set up your development tools (if not done already), learn how to add WebView2 code to a Win32 app project, and learn about WebView2 concepts along the way.

This tutorial starts by opening an existing Win32 app project that has WebView2 code added. The project uses the [Win32_GettingStarted (WebView2GettingStarted.sln)](https://github.com/MicrosoftEdge/WebView2Samples/tree/main/GettingStartedGuides/Win32_GettingStarted) directory that's part of the `WebView2Samples` repo. To use this article, you do the following:
Expand Down
2 changes: 2 additions & 0 deletions microsoft-edge/webview2/get-started/winforms.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ ms.date: 10/26/2022
---
# Get started with WebView2 in WinForms apps

This article is to learn to write your own WebView2 code. If you want to run a sample first, see [Win32 sample app](../samples/webview2apissample.md) or another sample app article, such as [WinForms sample app](../samples/webview2windowsformsbrowser.md).

<!--
todo: errors experienced with vs2022 by following these instructions:
* The addressbar text box & Go button shift to the right when alt+tab to the Form1 window.
Expand Down
Loading

0 comments on commit 1290722

Please sign in to comment.