示例#1
0
        /// <summary>
        /// Prompt the user for the name and parameters of a CDP method, then call it.
        /// </summary>
        public void CallCdpMethod()
        {
            TextInputDialog dialog = new TextInputDialog(
                "Call CDP Method",
                "CDP method name:",
                "Enter the CDP method name to call, followed by a space,\r\n" +
                "followed by the parameters in JSON format.",
                "Runtime.evaluate {\"expression\":\"alert(\\\"test\\\")\"}",
                false);

            if (dialog.ShowDialog() == true)
            {
                int    delimiterPos = dialog.Input.IndexOf(' ');
                string methodName   = dialog.Input.Substring(0, delimiterPos);
                string methodParams =
                    (delimiterPos < dialog.Input.Length
                        ? dialog.Input.Substring(delimiterPos + 1)
                        : "{}");

                _webView2.CallDevToolsProtocolMethod(
                    methodName,
                    methodParams,
                    (args) => {
                    MessageBox.Show(args.ReturnObjectAsJson, "CDP Method Result", MessageBoxButton.OK);
                });
            }
        }