Skip to content

Commit 1290722

Browse files
Merge pull request #3340 from MicrosoftDocs/user/mikehoffms/overview-apis-jan-2025
Move platform info from GetStart tut to general platform page
2 parents 609c577 + 6994c69 commit 1290722

18 files changed

Lines changed: 729 additions & 493 deletions

File tree

microsoft-edge/toc.yml

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,8 +1283,12 @@
12831283
items:
12841284
- name: Win32
12851285
items:
1286-
# - name: WebView2 in Win32 apps
1287-
# href: ./webview2/platforms/win32.md
1286+
- name: WebView2 in Win32 apps
1287+
href: ./webview2/platforms/win32.md
1288+
1289+
- name: Get started with WebView2 in Win32 apps
1290+
href: ./webview2/get-started/win32.md
1291+
displayName: Win32_GettingStarted # repo dir name
12881292

12891293
- name: Win32 sample app
12901294
href: ./webview2/samples/webview2apissample.md
@@ -1298,40 +1302,40 @@
12981302
href: ./webview2/samples/webview2browser.md
12991303
displayName: WebView2Browser # repo dir name
13001304

1301-
- name: Get started with WebView2 in Win32 apps
1302-
href: ./webview2/get-started/win32.md
1303-
displayName: Win32_GettingStarted # repo dir name
1304-
13051305
- name: WinUI 2 (UWP)
13061306
items:
1307-
# - name: WebView2 in WinUI 2 (UWP) apps
1308-
# href: ./webview2/platforms/winui2-uwp.md
1309-
1310-
- name: WinUI 2 (UWP) sample app
1311-
href: ./webview2/samples/webview2_sample_uwp.md
1312-
displayName: webview2_sample_uwp # repo dir name
1307+
- name: WebView2 in WinUI 2 (UWP) apps
1308+
href: ./webview2/platforms/winui2-uwp.md
13131309

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

1314+
- name: WinUI 2 (UWP) sample app
1315+
href: ./webview2/samples/webview2_sample_uwp.md
1316+
displayName: webview2_sample_uwp # repo dir name
1317+
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
1322-
1323-
- name: WinUI 3 (Windows App SDK) sample app
1324-
href: ./webview2/samples/webview2-winui3-sample.md
1325-
displayName: WebView2_WinUI3_Sample # repo dir name
1320+
- name: WebView2 in WinUI 3 (Windows App SDK) apps
1321+
href: ./webview2/platforms/winui3-windows-app-sdk.md
13261322

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

1331-
- name: WebView2 in WPF apps
1327+
- name: WinUI 3 (Windows App SDK) sample app
1328+
href: ./webview2/samples/webview2-winui3-sample.md
1329+
displayName: WebView2_WinUI3_Sample # repo dir name
1330+
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
1335+
1336+
- name: Get started with WebView2 in WPF apps
1337+
href: ./webview2/get-started/wpf.md
1338+
displayName: WPF_GettingStarted # repo dir name
13351339

13361340
- name: WPF sample app
13371341
href: ./webview2/samples/webview2wpfbrowser.md
@@ -1341,39 +1345,35 @@
13411345
href: ./webview2/samples/wv2cdpextensionwpfsample.md
13421346
displayName: WV2CDPExtensionWPFSample # repo dir name
13431347

1344-
- name: Get started with WebView2 in WPF apps
1345-
href: ./webview2/get-started/wpf.md
1346-
displayName: WPF_GettingStarted # repo dir name
1347-
13481348
- name: WinForms
13491349
items:
1350-
# - name: WebView2 in WinForms apps
1351-
# href: ./webview2/platforms/winforms.md
1352-
1353-
- name: WinForms sample app
1354-
href: ./webview2/samples/webview2windowsformsbrowser.md
1355-
displayName: WebView2WindowsFormsBrowser # repo dir name
1350+
- name: WebView2 in WinForms apps
1351+
href: ./webview2/platforms/winforms.md
13561352

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

1357+
- name: WinForms sample app
1358+
href: ./webview2/samples/webview2windowsformsbrowser.md
1359+
displayName: WebView2WindowsFormsBrowser # repo dir name
1360+
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
13681368
displayName: HoloLens2_GettingStarted # repo dir name
13691369

1370-
- name: WebView2 sample apps
1371-
href: ./webview2/code-samples-links.md # delete & redir?
1372-
13731370
- name: Getting Started tutorials
13741371
href: ./webview2/get-started/get-started.md # delete & redir?
13751372
displayName: GettingStartedGuides # repo dir name
13761373

1374+
- name: WebView2 sample apps
1375+
href: ./webview2/code-samples-links.md # delete & redir?
1376+
13771377
# -----------------------------------------------------------------------------
13781378
- name: Navigation, events, and authentication
13791379
items:

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2986,6 +2986,7 @@ Use the following APIs to forward `IDropTarget` events from the system to the We
29862986

29872987
---
29882988

2989+
29892990
<!-- ------------------------------ -->
29902991
#### Accessibility
29912992

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ ms.date: 02/22/2023
1010
---
1111
# Getting Started tutorials
1212

13-
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.
13+
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.
14+
1415

1516
| Article | Completed project | Description |
1617
|---|---|---|

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

Lines changed: 2 additions & 189 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ ms.date: 11/25/2024
1212

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

15+
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.
16+
1517
> [!IMPORTANT]
1618
> 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.
1719
@@ -409,195 +411,6 @@ public class WebViewExample : MonoBehaviour, IWithPostMessage
409411
```
410412

411413

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-
600-
601414
<!-- ====================================================================== -->
602415
## See also
603416

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ ms.date: 07/29/2022
1212

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

15+
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.
16+
1517
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.
1618

1719
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:

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ ms.date: 10/26/2022
1010
---
1111
# Get started with WebView2 in WinForms apps
1212

13+
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).
14+
1315
<!--
1416
todo: errors experienced with vs2022 by following these instructions:
1517
* The addressbar text box & Go button shift to the right when alt+tab to the Form1 window.

0 commit comments

Comments
 (0)