WebVR in WebView
06/12/2018
閱讀時間 2 分鐘
本文內容
As of the Windows 10 April 2018 Update (version 1803, build 17134, EdgeHTML 17), WebVR is supported in WebView controls in Windows 10 apps. The WebView control enables you to host web content in your Windows 10 app. See Microsoft Edge WebView for Windows 10 apps for more information about WebView.
Add WebVR support to a WebView control
In order for your WebView control to host WebVR content, there are a few steps you'll have to take.
Initialize the WebView programmatically to run in a separate process. You'll have to declare, initialize, and add it to the UI programmatically (rather than declaratively in the XAML or HTML).
Add a PermissionRequested event handler for the WebView. In it, allow the permission request.
The following sample declares and initializes a WebView, handles the PermissionRequested event, adds the WebView to the UI, and navigates to a WebVR site.
WebView webView;
public MainPage()
{
this.InitializeComponent();
webView = new WebView(WebViewExecutionMode.SeparateProcess);
webView.PermissionRequested += MyWebView_PermissionRequested;
MyGrid.Children.Add(webView);
Grid.SetRow(webView, 1);
webView.Navigate("https://webvr.info/samples/03-vr-presentation.html");
}
private void MyWebView_PermissionRequested(
WebView sender, WebViewPermissionRequestedEventArgs args)
{
args.PermissionRequest.Allow();
}
let wvprocess = new MSWebViewProcess();
// WebViews created with the same MSWebViewProcess object share the same process
wvprocess.CreateWebViewAsync().then(function (webview) {
webview.navigate("https://webvr.info/samples/03-vr-presentation.html");
document.body.appendChild(webview);
webview.addEventListener("MSWebViewPermissionRequested", e => {
e.permissionRequest.allow();
});
});
See also