/// <summary> /// Execute JavaScript code from the javascript parameter in the /// current top level document rendered in the WebView. This will execute /// asynchronously and when complete, if a handler is provided in the /// ExecuteScriptCompletedHandler parameter, its Invoke method will be /// called with the result of evaluating the provided JavaScript. The result /// value is a JSON encoded string. /// If the result is undefined, contains a reference cycle, or otherwise /// cannot be encoded into JSON, the JSON null value will be returned as the /// string 'null'. Note that a function that has no explicit return value /// returns undefined. /// If the executed script throws an unhandled exception, then the result is /// also 'null'. /// This method is applied asynchronously. If the call is made while the /// webview is on one document, and a navigation occurs after the call is /// made but before the JavaScript is executed, then the script will not be /// executed and the handler will be called with E_FAIL for its errorCode /// parameter. /// ExecuteScript will work even if IsScriptEnabled is set to FALSE. /// </summary> /// <param name="javaScript"></param> /// <param name="callback"></param> public void ExecuteScript(string javaScript, Action <ExecuteScriptCompletedEventArgs> callback) { if (_webView2WebView == null) { return; } _webView2WebView.ExecuteScript(javaScript, callback); }