How to make 'ontounchend in document' return true in WebView2

59 views Asked by At

In WebView2 browser, I want to move things with finger. But it does not support ontouchxxx(ontouchstart, ontouchend). In other word, "ontouchend" in document returns false.

I tried various ways as followings but it doesn't work.

webView2 = new Microsoft.Web.WebView2.WinForms.WebView2();
  1. setTouchEmulationEnabled
    await webView2.EnsureCoreWebView2Async(null);
    if (webView2.CoreWebView2 != null)
    {
        webView2.CoreWebView2.CallDevToolsProtocolMethodAsync("Emulation.setEmitTouchEventsForMouse", "{'enabled': true }");
    }
  1. --enable-features=msWebView2EnableDraggableRegions
    string arg = @"--enable-features=""msWebView2EnableDraggableRegions""";
    var opts = new CoreWebView2EnvironmentOptions { AdditionalBrowserArguments = arg };
    var webView2Environment = await CoreWebView2Environment.CreateAsync(null, null, opts);
    await webView21.EnsureCoreWebView2Async(webView2Environment);
  1. IsSwipeNavigationEnabled
    await webView2.EnsureCoreWebView2Async(null);
    if (webView2.CoreWebView2 != null)
    {
        webView2.CoreWebView2.Settings.IsSwipeNavigationEnabled = true;
    }
  1. Change UserAgent like iPad emulator of chrome,edge which return true for "ontouchend" in document
     await webView2.EnsureCoreWebView2Async(null);
     if (webView2.CoreWebView2 != null)
     {
         webView2.CoreWebView2.Settings.UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Safari/605.1.15";
     }
1

There are 1 answers

0
Xudong Peng On

In my opinion, this is by design, since this API only works on touch devices, if you want to implement such functionality on pc browser, I think you may need to use some other plugin.