/// <summary> /// Post the specified webMessage to the top level document in this /// IWebView2WebView. The top level document's window.chrome.webview's message /// event fires. JavaScript in that document may subscribe and unsubscribe to /// the event via the following: /// ``` /// window.chrome.webview.addEventListener('message', handler) /// window.chrome.webview.removeEventListener('message', handler) /// ``` /// The event args is an instance of `MessageEvent`. /// The IWebView2Settings::IsWebMessageEnabled setting must be true or this method /// will fail with E_INVALIDARG. /// The event arg's data property is the webMessage string parameter parsed /// as a JSON string into a JavaScript object. /// The event arg's source property is a reference to the /// `window.chrome.webview` object. /// See SetWebMessageReceivedEventHandler for information on sending messages /// from the HTML document in the webview to the host. /// This message is sent asynchronously. If a navigation occurs before the /// message is posted to the page, then the message will not be sent. /// </summary> /// <param name="json"></param> public void PostWebMessageAsJson(string json) { if (_webView2WebView != null) { _webView2WebView.PostWebMessageAsJson(json); } }