title: How detect a mouse click in webview2 (c#/vb.net)
body: <p>I try to get the events click of html element.
  With a WebBrowser I used :</p>
  <pre><code>instance = Nothing
              instance = WebBrowser1.Document
              AddHandler instance.Click, AddressOf Document_Click
  </code></pre>
  <p>But with Webview2 I don't find the good practice. I must inject a javascript code ?
  But, how I get the handlder in C# or Vb.net application ?</p>
  <p>Thanks a lot.</p>
  <p>Here a sample code. I don't have the return in my function : WebView1_WebMessageReceived. Why ?
  I think, I forgot something....</p>
  <pre><code>Imports System.IO
  Imports Microsoft.Web.WebView2.Core
  Imports Newtonsoft.Json
  
  
      Class MainWindow
          Public Sub New()
      
              InitializeComponent()
              InitializeSyncroComponent()
      
              ' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
      
          End Sub
      
          Structure JsonObject
              Public Key As String
              'Public Value As PointF
          End Structure
      
          Async Sub InitializeSyncroComponent()
              Await webview1.EnsureCoreWebView2Async
              webview1.CoreWebView2.Navigate(&quot;https://google.fr/&quot;)
          End Sub
      
          Private Sub WebView1_WebMessageReceived(ByVal sender As Object, ByVal e As Microsoft.Web.WebView2.Core.CoreWebView2WebMessageReceivedEventArgs)
              Dim jsonObject As JsonObject = JsonConvert.DeserializeObject(Of JsonObject)(e.WebMessageAsJson)
      
              Select Case jsonObject.Key
                  Case &quot;contextmenu&quot;
                      'contextMenuStrip1.Show(Point.Truncate(jsonObject.Value))
                  Case &quot;mousedown&quot;
                      Stop
                      ' contextMenuStrip1.Hide()
              End Select
          End Sub
      
          Private Sub webview1_NavigationCompleted(sender As Object, e As CoreWebView2NavigationCompletedEventArgs) Handles webview1.NavigationCompleted
              webview1.CoreWebView2.Settings.AreDefaultContextMenusEnabled = False
              Dim script As String = File.ReadAllText(&quot;d:\test_mouse.js&quot;)
              webview1.CoreWebView2.AddScriptToExecuteOnDocumentCreatedAsync(script)
          End Sub
      End Class
  </code></pre>
  <p>Script Java:</p>
  <pre><code>document.addEventListener('mousedown', function (event)
  {
      let jsonObject =
      {
          Key: 'mousedown',
          Value:
          {
              X: event.screenX,
              Y: event.screenY
          }
      };
      window.chrome.webview.postMessage(jsonObject);
  });
  </code></pre>
  <p><strong>Edit</strong>:
  I found my error...
  it was really not much !</p>
  <p>I had forgot the déclaration of the WebMessageReceived in the webview property.</p>
  <p><a href="https://i.stack.imgur.com/JW42x.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JW42x.png" alt="Webview Property" /></a></p>