Ejemplo n.º 1
0
 /// <summary>
 /// Prompt the user for some script and then execute it.
 /// </summary>
 public void InjectScript()
 {
     TextInputDialog dialog = new TextInputDialog(
         "Inject Script",
         "Enter script code:",
         "Enter the JavaScript code to run in the webview.",
         "window.getComputedStyle(document.body).backgroundColor",
         false);
     if (dialog.ShowDialog() == DialogResult.OK)
     {
         _webView2.ExecuteScript(dialog.Input, (args) =>
         {
             if (args.ErrorCode != 0)
             {
                 CommonDialogs.ShowFailure(args.ErrorCode, "ExecuteScript failed");
             }
             MessageBox.Show(args.ResultAsJson, "ExecuteScript Result", MessageBoxButtons.OK);
         });
     }
 }