示例#1
0
        public void LogoutEMail()
        {
            IBrowser b     = this.browser.GetBrowser();
            IFrame   frame = b.GetFrame("emailLogin");

            frame.EvaluateScriptAsync("App.logout();");
        }
示例#2
0
        bool IContextMenuHandler.OnContextMenuCommand(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags)
        {
            //if ((int)commandId == ShowDevTools)
            //{
            //    browser.ShowDevTools();
            //}
            //if ((int)commandId == CloseDevTools)
            //{
            //    browser.CloseDevTools();
            //}
            if ((int)commandId == ShowFind)
            {
                showFind();
            }
            else if ((int)commandId == CopyUrl)
            {
                System.Windows.Forms.Clipboard.SetText(browser.MainFrame.Url);
            }

            frame.EvaluateScriptAsync(scriptWithMousePos(parameters.XCoord, parameters.YCoord)).ContinueWith(async(resp) =>
            {
                var r = await resp;
                if (r.Success)
                {
                    //MessageBox.Show(r.Result.ToString());
                }
            });

            return(false);
        }
示例#3
0
        bool IJsDialogHandler.OnJSDialog(IWebBrowser browserControl, IBrowser browser, string originUrl, string acceptLang, CefJsDialogType dialogType, string messageText, string defaultPromptText, IJsDialogCallback callback, ref bool suppressMessage)
        {
            if (messageText == "欢迎登录邮箱")
            {
                IFrame frame = browser.GetFrame("emailLogin");

                Match mUrl = Regex.Match(frame.Url, @"(http:\/\/" + SysParams.MailWeb + @"\/)(\?login\=1)?", RegexOptions.IgnoreCase);

                if (mUrl.Groups[1].Success)
                {
                    if (mUrl.Groups[2].Success)
                    {
                        string js = string.Format(@"document.getElementById('selenium_login_email').value='{0}';", mailAccount);
                        js += string.Format(@"document.getElementById('selenium_login_password').value='{0}';", mailPassWord);
                        js += @"document.getElementById('selenium_login_signin_button').click();";

                        frame.EvaluateScriptAsync(js);
                    }
                    else
                    {
                        //LoadUrl(string.Format(SysParams.Page_PersonalInfo, SysParams.AppServer, "123"));
                    }
                }

                //suppressMessage = false;

                //return true;
            }
            return(false);
        }
示例#4
0
        /// <summary>
        /// Determine if the frame contains an element with the specified id.
        /// </summary>
        /// <param name="frame">Test the elements in this frame.</param>
        /// <param name="id">The id to find.</param>
        /// <returns>True if an element with the specified id exists in the frame.</returns>
        public static async Task <bool> ElementWithIdExists(this IFrame frame, string id)
        {
            if (frame == null)
            {
                throw new ArgumentException("An IFrame instance is required.", "frame");
            }

            var script =
                @"(function () {
                    var n = document.getElementById('##ID##');
                    return n !== null && typeof n !== 'undefined';
                })();";

            // For simple inline scripts you could use String.Format() but
            // beware of braces in the javascript code. If reading from a file
            // it's probably safer to include tokens that can be replaced via
            // regex.
            script = Regex.Replace(script, "##ID##", id);

            var response = await frame.EvaluateScriptAsync(script);

            if (!response.Success)
            {
                throw new Exception(response.Message);
            }

            return((bool)response.Result);
        }
示例#5
0
        public Task <JavascriptResponse> ExecJs(IFrame frame, string text)
        {
            if (frame == null || string.IsNullOrEmpty(text))
            {
                Log.ShowLog(TAG, "do not run this js");
                return(null);
            }

            Log.ShowLog(TAG, "exec js on url " + frame.Url + "\n" + "js: " + text);

            var task = frame.EvaluateScriptAsync(text, null);

            if (task != null)
            {
                //  task.Wait();
                if (!task.IsFaulted)
                {
                    return(task);
                }
            }

            return(null);

            //task.ContinueWith(t =>
            //{
            //    if (!t.IsFaulted)
            //    {
            //        var response = t.Result;
            //        Log.ShowLog(TAG, "response:" + response.Result + " Message :" +
            //            response.Message + " success:" + response.Success);
            //    }
            //});
        }
        public static async Task <bool> OpenLogicPage(this IFrame frame)
        {
            if (frame == null)
            {
                throw new ArgumentException("An IFrame instance is required.", "frame");
            }

            // Scripts should be minified for production builds. The script
            // could also be read from a file...
            const string script =
                @"(function ()
                {
                    var success = true;
                    var logiclink = document.getElementsByName('pctbsy_index_ljdl_01');
                    if ((logiclink != null) && (logiclink[0] != null))
                        logiclink[0].click();
                    return success;
                })();";

            var response = await frame.EvaluateScriptAsync(script);

            if (!response.Success)
            {
                throw new Exception(response.Message);
            }

            return((bool)response.Result);
        }
        public static async Task <bool> GangBengKamiOk(this IFrame frame)
        {
            if (frame == null)
            {
                throw new ArgumentException("An IFrame instance is required.", "frame");
            }

            // Scripts should be minified for production builds. The script
            // could also be read from a file...
            string script =
                @"(function ()
                    {
                        var success = true;
                    
                        var okbtns = document.getElementsByClassName('ui-btn');
                        if(okbtns!= null)
                            okbtns[0].click();

                        return success;
                    })();";

            var response = await frame.EvaluateScriptAsync(script);

            if (!response.Success)
            {
                throw new Exception(response.Message);
            }

            return((bool)response.Result);
        }
示例#8
0
        public static async Task <bool> EnableJQ(IFrame frame)
        {
            var t = await frame.EvaluateScriptAsync(
                @"(function(){
                    if(typeof jQuery == 'undefined')return false;
                    else return true;
                }());"
                ).ContinueWith(result => {
                if (result != null && result.Result.Success)
                {
                    try
                    {
                        return((bool)result.Result.Result);
                    }
                    catch (Exception)
                    {
                        return(false);
                    }
                }
                return(false);
            });

            Console.WriteLine("Supoort JQ =" + t);
            return(t);
        }
示例#9
0
        public static async Task <TaskResult <string> > isFrameContentBlocked(IFrame frame, TimeSpan readTimeout)
        {
            TaskResult <string> result = new TaskResult <string>("");

            bool isBlocked = false;

            if (frame.IsValid && frame.Url != FilteredCommon.Filtering.FilteringFlow.blockedDevUrl)
            {
                try
                {
                    var headerRes = await frame.EvaluateScriptAsync(
                        FilteredCommon.Filtering.FilteringFlow.evalHead,
                        timeout : readTimeout
                        );

                    var bodyRes = await frame.EvaluateScriptAsync(
                        FilteredCommon.Filtering.FilteringFlow.evalBody,
                        timeout : readTimeout
                        );

                    if (headerRes.Success && bodyRes.Success)
                    {
                        // No time block in content!! Let loaded data before curfew stay!
                        string finalResaon = "";
                        isBlocked = FilteredCommon.Filtering.FilteringFlow.isHTMLPageBlocked(
                            BrowserForm.httpPolicy,
                            headerRes.Result as string,
                            bodyRes.Result as string,
                            out finalResaon
                            );
                        if (isBlocked)
                        {
                            finalResaon += " <br /> Source frame url: " + frame.Url;

                            result.Sucess = true;
                            result.Result = finalResaon;
                        }
                    }
                }
                catch (Exception ex)
                {
                    // Do nothing?
                }
            }

            return(result);
        }
        public static async Task <string> ReadTongGangKamiResult(this IFrame frame)
        {
            if (frame == null)
            {
                throw new ArgumentException("An IFrame instance is required.", "frame");
            }

            // Scripts should be minified for production builds. The script
            // could also be read from a file...
            string script =
                @"(function ()
                    {
                        var Success = true;
                        var Message = null;

                        //处理结果
                        //抱歉,兑换码不存在
                        //抱歉,兑换码已使用
                        var resulterrordlg = document.getElementsByClassName('dialog result Copper hide');
                        //兑换码余额100.00 手续费1.00 本月已获取10次
                        var resultokdlg = document.getElementsByClassName('dialog double Copper hide');
 
                        if ((resulterrordlg != null) && (resulterrordlg[0].style.display == 'block'))
                        {
                            var msg = resulterrordlg[0].getElementsByClassName('res');
                            if ((msg != null) && (msg[0] != null))
                                Message = msg[0].innerText;

                            var okbtn = resulterrordlg[0].getElementsByClassName('confirm');
                            if ((okbtn != null) && (okbtn[0] != null))
                                okbtn[0].click();
                        }
                        else if ((resultokdlg != null) && (resultokdlg[0].style.display == 'block'))
                        {
                            var msg = resultokdlg[0].getElementsByClassName('res');
                            if ((msg != null) && (msg[0] != null))
                                Message = msg[0].innerText;

                            var okbtn = resultokdlg[0].getElementsByClassName('confirm');
                            if ((okbtn != null) && (okbtn[0] != null))
                                okbtn[0].click();

                            Success = false;
                        }

                        return Message;
                    })();";

            var response = await frame.EvaluateScriptAsync(script);

            if (!response.Success)
            {
                throw new Exception(response.Message);
            }
            return((string)(response.Result));
        }
示例#11
0
        public static object EvaluateScript(this IFrame Frame, string Script)
        {
            if (Program.Debug)
            {
                Program.Writer?.WriteLine("EVAL At: {0}\r\nScript: {1}", Frame.Url, Script);
            }

            Frame.WaitForLoad();

            return(Frame.EvaluateScriptAsync(Script).GetAwaiter().GetResult().Result);
        }
        private static void ExecuteScriptInMainFrameSafe(IBrowser browser, string script, string url)
        {
            if (browser.IsDisposed)
            {
                return;
            }
            IFrame mainFrame = browser.MainFrame;

            if (mainFrame.IsDisposed)
            {
                return;
            }
            mainFrame.EvaluateScriptAsync(script, url, 1, new TimeSpan?());
        }
示例#13
0
        public static bool IsLoading(this IFrame Frame)
        {
            if (Frame.Browser.IsLoading)
            {
                return(true);
            }
            var Status = (string)Frame.EvaluateScriptAsync(Properties.Resources.GetDocumentStatus).GetAwaiter().GetResult().Result;

            if (Status?.Trim().ToLower() == "complete")
            {
                return(false);
            }
            return(true);
        }
示例#14
0
        private string RunScript(string script)
        {
            script =
                "(function() " +
                "{ " +
                script +
                "})();";
            string result = (string)frame.EvaluateScriptAsync(script, null)?.Result?.Result;

            if (result == null)
            {
                this.Invoke(new Action(() => textBox1.AppendText("Failed to run the script: " + script + Environment.NewLine)));
                throw new Exception("");
            }
            return(result);
        }
示例#15
0
        private Task <JavascriptResponse> test()
        {
//            function myFunction()
//{
//                return document.getElementById('kw').value;
//            }
//            myFunction();

            var jspstring = jsptext.Text;

            Log.ShowLog(TAG, "jsptext is  : " + jspstring);

            var selecturl = framecheckboxlist.SelectedItem;

            if (selecturl == null || string.IsNullOrEmpty(selecturl.ToString()))
            {
                return(null);
            }

            var    identifiers = browser.GetBrowser().GetFrameIdentifiers();
            IFrame frame       = null;

            foreach (var i in identifiers)
            {
                if (browser.GetBrowser().GetFrame(i).Url.Equals(selecturl))
                {
                    frame = browser.GetBrowser().GetFrame(i);
                }
            }

            var task = frame?.EvaluateScriptAsync(jspstring, null);

            //    task?.Wait();
            Log.ShowLog(TAG, "task run end");

            //task?.ContinueWith(t =>
            //{
            //    if (!t.IsFaulted)
            //    {
            //        var response = t.Result;
            //        Log.ShowLog(TAG, "response:" + response.Result + " Message :" +
            //            response.Message + " success:" + response.Success);
            //    }
            //});
            return(task);
        }
        public static async Task <bool> InputGangBengKami(this IFrame frame, string kami0, string kami1, string kami2, string kami3)
        {
            if (frame == null)
            {
                throw new ArgumentException("An IFrame instance is required.", "frame");
            }

            // Scripts should be minified for production builds. The script
            // could also be read from a file...
            string script =
                @"(function ()
                    {
                        var success = true;
                    
                        var cards = document.getElementsByName('cardpass');
                        cards[0].value = '##ID1##';
                        cards[1].value = '##ID2##';
                        cards[2].value = '##ID3##';
                        cards[3].value = '##ID4##';

                        //立即兑换
                        var lijiduihuanbtns = document.getElementsByClassName('ex-btn');
                        lijiduihuanbtns[0].click();

                        return success;
                    })();";

            // For simple inline scripts you could use String.Format() but
            // beware of braces in the javascript code. If reading from a file
            // it's probably safer to include tokens that can be replaced via
            // regex.
            script = Regex.Replace(script, "##ID1##", kami0);
            script = Regex.Replace(script, "##ID2##", kami1);
            script = Regex.Replace(script, "##ID3##", kami2);
            script = Regex.Replace(script, "##ID4##", kami3);

            var response = await frame.EvaluateScriptAsync(script);

            if (!response.Success)
            {
                throw new Exception(response.Message);
            }

            return((bool)response.Result);
        }
        public static async Task <string> ReadGangBengKamiResult(this IFrame frame)
        {
            if (frame == null)
            {
                throw new ArgumentException("An IFrame instance is required.", "frame");
            }

            // Scripts should be minified for production builds. The script
            // could also be read from a file...
            string script =
                @"(function ()
                    {
                        var Success = true;
                        var Message = null;

                        //查找确认兑换对话框
                        var mekesuremsgpopdlg = document.getElementById('J_cardMsgPop');
                        if((mekesuremsgpopdlg!=null)&&(mekesuremsgpopdlg.style.display=='block'))
                        {
                            var msgs = document.getElementsByClassName('kami-msg');
                            Message = msgs[0].innerText;

                            var surebtn = document.getElementById('J_cardBtn');
                            if(surebtn!= null)
                                surebtn.click();
                        }
                        else
                        {
                            var error = document.getElementsByClassName('error-font');
                            Message = error[0].innerText;
                            Success = false;
                        }

                        return Message;
                    })();";

            var response = await frame.EvaluateScriptAsync(script);

            if (!response.Success)
            {
                throw new Exception(response.Message);
            }
            return((string)(response.Result));
        }
示例#18
0
        public static async Task <object> DoFunc(IFrame fram, string func)
        {
            //Console.WriteLine("Excute Function {"+func+"}");
            func = GetOriginal(func);
            var t = await fram.EvaluateScriptAsync("(function(){" + func + "}());").ContinueWith(r => {
                if (r.Result.Success)
                {
                    LogHelper.Debug(string.Format("函数[{0}]执行成功,返回值为[{1}]", func, r.Result.Result));
                    return(r.Result.Result);
                }
                else
                {
                    LogHelper.Debug(string.Format("函数[{0}]执行失败,{1}", func, r.Result.Message));
                }
                return(null);
            });

            return(t);
        }
示例#19
0
        public static async Task <object> GetBaseFunc(IFrame frame, string target, string functionString)
        {
            target         = target.Replace("\"", "");;
            functionString = functionString.Replace("\"", "");
            var t = await frame.EvaluateScriptAsync("(function(){ return $('" + target + "')." + functionString + ";}());").ContinueWith(
                r =>
            {
                var result = r.Result;
                if (result != null && result.Success)
                {
                    LogHelper.Debug(string.Format("函数 {0} 执行成功 结果为{1}", " function(){ return $('" + target + "')." + functionString + ";}", result.Result));
                    return(result.Result);
                }
                LogHelper.Debug("GetBaseFunc Error  " + r.Result.Message);
                return(null);
            });

            return(t);
        }
示例#20
0
        private List <int> getElementDimension(IFrame frame, string className)
        {
            var dims = new List <int>();
            //var frame = Program.Windows.Items["landingPage"].Browser.GetMainFrame();
            var task = frame.EvaluateScriptAsync(
                "(function(){var el = document.getElementsByClassName('" + className + "')[0];return [el.offsetWidth, el.offsetHeight];})();"
                );

            task.Wait();
            if (task.Result.Success)
            {
                var list = task.Result.Result as System.Collections.IEnumerable;
                foreach (object item in list)
                {
                    dims.Add(Convert.ToInt16(item));
                }
            }
            return(dims);
        }
        public static async Task <bool> InputTongGangKami(this IFrame frame, string kami)
        {
            if (frame == null)
            {
                throw new ArgumentException("An IFrame instance is required.", "frame");
            }

            // Scripts should be minified for production builds. The script
            // could also be read from a file...
            string script =
                @"(function ()
                    {
                        var success = true;
                    
                        //输入卡密
                        var input = document.getElementsByName('copperCode');
                        if ((input != null) && (input[0] != null))
                            input[0].value = '##ID1##';

                        //立即兑换
                        var duihuanbtn = document.getElementsByName('pctbsy_index_dh_01');
                        if ((duihuanbtn != null) && (duihuanbtn[0] != null))
                            duihuanbtn[0].click();

                        return success;
                    })();";

            // For simple inline scripts you could use String.Format() but
            // beware of braces in the javascript code. If reading from a file
            // it's probably safer to include tokens that can be replaced via
            // regex.
            script = Regex.Replace(script, "##ID1##", kami);

            var response = await frame.EvaluateScriptAsync(script);

            if (!response.Success)
            {
                throw new Exception(response.Message);
            }

            return((bool)response.Result);
        }
示例#22
0
        /// <summary>
        /// Determine if the active element in a frame accepts text input.
        /// </summary>
        /// <param name="frame">Test the active element in this frame.</param>
        /// <returns>True if the active element accepts text input.</returns>
        public static async Task <bool> ActiveElementAcceptsTextInput(this IFrame frame)
        {
            if (frame == null)
            {
                throw new ArgumentException("An IFrame instance is required.", "frame");
            }

            // Scripts should be minified for production builds. The script
            // could also be read from a file...
            const string script =
                @"(function ()
                    {
                        var isText = false;
                        var activeElement = document.activeElement;
                        if (activeElement) {
                            if (activeElement.tagName.toLowerCase() === 'textarea') {
                                isText = true;
                            } else {
                                if (activeElement.tagName.toLowerCase() === 'input') {
                                    if (activeElement.hasAttribute('type')) {
                                        var inputType = activeElement.getAttribute('type').toLowerCase();
                                        if (inputType === 'text' || inputType === 'email' || inputType === 'password' || inputType === 'tel' || inputType === 'number' || inputType === 'range' || inputType === 'search' || inputType === 'url') {
                                            isText = true;
                                        }
                                    }
                                }
                            }
                        }
                        return isText;
                    })();";

            var response = await frame.EvaluateScriptAsync(script);

            if (!response.Success)
            {
                throw new Exception(response.Message);
            }

            return((bool)response.Result);
        }
示例#23
0
        public static async Task <System.Collections.IList> GetArrayBase(IFrame frame, string target, string functionString)
        {
            target         = target.Replace("\"", "");
            functionString = functionString.Replace("\"", "");

            var t = await frame.EvaluateScriptAsync(@"(function(){ var list = []; $('" + target + "').each(function(){ list.push($(this)." + functionString + ");}); return list;}());").ContinueWith(
                ts =>
            {
                if (ts != null && ts.Result.Success)
                {
                    LogHelper.Debug(string.Format("函数 {0} => {1} 执行成功 结果为{2}", functionString, target, ts.Result));
                    return((System.Collections.IList)ts.Result.Result);
                }
                else
                {
                    Console.WriteLine("GetArrayBase Error : " + ts.Result.Message);
                }
                return(null);
            });

            return(t);
        }
示例#24
0
        /// <summary>
        /// The evaluate.
        /// </summary>
        /// <param name="request">
        /// The request.
        /// </param>
        /// <returns>
        /// The <see cref="ChromelyResponse"/>.
        /// </returns>
        private ChromelyResponse Evaluate(ChromelyRequest request)
        {
            var response = new ChromelyResponse(request.Id);

            response.ReadyState = (int)ReadyState.ResponseIsReady;
            response.Status     = (int)System.Net.HttpStatusCode.OK;
            response.StatusText = "OK";
            response.Data       = DateTime.Now.ToLongDateString();

            try
            {
                ScriptInfo scriptInfo = new ScriptInfo(request.PostData);
                IFrame     frame      = FrameHandler.GetFrame(scriptInfo.FrameName);
                if (frame == null)
                {
                    response.Data = $"Frame {scriptInfo.FrameName} does not exist.";
                    return(response);
                }

                Task <JavascriptResponse> javascriptResponse = frame.EvaluateScriptAsync(scriptInfo.Script);
                javascriptResponse.Wait();
                string status = javascriptResponse.Result.Success
                                    ? "Successfully executed :"
                                    : "Error in executing :";

                response.Data = string.IsNullOrEmpty(javascriptResponse.Result?.Result?.ToString())
                                    ? status + scriptInfo.Script
                                    : javascriptResponse.Result?.Result?.ToString();
                return(response);
            }
            catch (Exception e)
            {
                response.ReadyState = (int)ReadyState.RequestReceived;
                response.Status     = (int)System.Net.HttpStatusCode.BadRequest;
                response.StatusText = "Error";
            }

            return(response);
        }
示例#25
0
        private void timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            if (owner == null || browser == null)
            {
                return;
            }

            if (needsCleanup)
            {
                if (!owner.ContainsFocus)
                {
                    using (IFrame frame = browser.MainFrame){
                        frame.EvaluateScriptAsync(script).ContinueWith(task => {
                            JavascriptResponse response = task.Result;

                            if (response.Success && (response.Result as bool? ?? false))
                            {
                                SetNeedsCleanup(false);
                                owner.InvokeAsyncSafe(() => owner.TriggerAnalyticsEvent(Analytics.AnalyticsFile.Event.GCReload));
                            }
                        });
                    }
                }
            }
            else
            {
                try{
                    using (Process process = BrowserProcesses.FindProcess(browser)){
                        if (process?.PrivateMemorySize64 > threshold)
                        {
                            SetNeedsCleanup(true);
                        }
                    }
                }catch {
                    // ignore I guess?
                }
            }
        }
            private void InnerFlushScripts()
            {
                ScriptTask scriptToEvaluate = null;
                var        scriptsToExecute = new List <ScriptTask>();

                do
                {
                    var scriptTask = PendingScripts.Take(FlushTaskCancelationToken.Token);
                    if (scriptTask.WaitHandle == null)
                    {
                        scriptsToExecute.Add(scriptTask);
                    }
                    else
                    {
                        scriptToEvaluate = scriptTask;
                        break; // this script result needs to be handled separately
                    }
                } while (PendingScripts.Count > 0);

                if (scriptsToExecute.Count > 0)
                {
                    var script = string.Join(";" + Environment.NewLine, scriptsToExecute.Select(s => s.Script));
                    if (frame.IsValid)
                    {
                        var frameName = frame.Name;
                        var task      = frame.EvaluateScriptAsync(
                            WrapScriptWithErrorHandling(script),
                            timeout: OwnerWebView.DefaultScriptsExecutionTimeout);
                        task.Wait(FlushTaskCancelationToken.Token);
                        var response = task.Result;
                        if (!response.Success)
                        {
                            var evaluatedScriptFunctions = scriptsToExecute.Select(s => s.FunctionName);
                            OwnerWebView.ExecuteWithAsyncErrorHandlingOnFrame(() => throw ParseResponseException(response, evaluatedScriptFunctions), frameName);
                        }
                    }
                }

                if (scriptToEvaluate != null)
                {
                    // evaluate and signal waiting thread
                    Task <JavascriptResponse> task = null;
                    var script  = scriptToEvaluate.Script;
                    var timeout = scriptToEvaluate.Timeout ?? OwnerWebView.DefaultScriptsExecutionTimeout;
                    try {
                        if (frame.IsValid)
                        {
                            task = frame.EvaluateScriptAsync(script, timeout: timeout);
                            task.Wait(FlushTaskCancelationToken.Token);
                            scriptToEvaluate.Result = task.Result;
                        }
                    } catch (Exception e) {
                        if (task?.IsCanceled == true)
                        {
                            // timeout
                            scriptToEvaluate.Exception = new JavascriptException("Timeout", (timeout.HasValue ? $"More than {timeout.Value.TotalMilliseconds}ms elapsed" : "Timeout ocurred") + $" evaluating the script: '{script}'");
                        }
                        else
                        {
                            scriptToEvaluate.Exception = e;
                        }
                    } finally {
                        scriptToEvaluate.WaitHandle.Set();
                    }
                }
            }
示例#27
0
        private void _gatewayTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            _gatewayTimer.Stop();
            if (!GatewayEnabled)
            {
                return;
            }
            for (object actionObject; (actionObject = GetGatewayAction()) != null;)
            {
                GatewayAction.BaseObject action = (GatewayAction.BaseObject)actionObject;
                switch (action.ActionType)
                {
                case GatewayAction.GatewayActionType.GetParentFrameNames:
                {
                    GatewayAction.GetParentFrames frameAction = (GatewayAction.GetParentFrames)action;
                    _webBrowser.Dispatcher.Invoke(() =>
                        {
                            IFrame frame = null;
                            foreach (string frameName in  _webBrowser.Browser.GetBrowser().GetFrameNames())
                            {
                                if (frameAction.StartingFrame.IsRegex.Value &&
                                    Regex.IsMatch(frameName, frameAction.StartingFrame.Value.Value))
                                {
                                    frame = _webBrowser.Browser.GetBrowser().GetFrame(frameName);
                                }
                                else if (!frameAction.StartingFrame.IsRegex.Value && frameName == frameAction.StartingFrame.Value.Value)
                                {
                                    frame = _webBrowser.Browser.GetBrowser().GetFrame(frameName);
                                }
                            }
                            if (frame != null)
                            {
                                //frameAction.RecursiveFrameList.Add(new FrameDetails() { ExpectedFrameName = frame.AttributeName, Url = frame.Url });
                                while (true)
                                {
                                    frameAction.RecursiveFrameList.Add(new FrameDetails()
                                    {
                                        FrameName = frame.Name, Url = frame.Url
                                    });
                                    if (frame.Parent != null)
                                    {
                                        frame = frame.Parent;
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                                frameAction.Success = true;
                            }
                        });
                    frameAction.Completed = true;
                }
                break;

                case GatewayAction.GatewayActionType.FindElementsFrame:
                {
                    GatewayAction.FindElementsFrame findingAction = (GatewayAction.FindElementsFrame)action;
                    _webBrowser.Dispatcher.Invoke(async() =>
                        {
                            foreach (string frameName in _webBrowser.Browser.GetBrowser().GetFrameNames())
                            {
                                IFrame frame = _webBrowser.Browser.GetBrowser().GetFrame(frameName);
                                var result   = await frame.EvaluateScriptAsync(findingAction.EvaluationScript);
                                if (result.Success)
                                {
                                    if ((bool)result.Result)
                                    {
                                        findingAction.FrameName = frameName;
                                        findingAction.Success   = true;
                                        break;
                                    }
                                }
                            }
                        });
                    findingAction.Completed = true;
                }
                break;

                case GatewayAction.GatewayActionType.EvaluateJavascript:
                {
                    GatewayAction.EvaluateJavascript evaluationAction = (GatewayAction.EvaluateJavascript)action;
                    _webBrowser.Dispatcher.Invoke(async() =>
                        {
                            while (true)
                            {
                                IFrame frame = null;
                                if (evaluationAction.FrameName == null)
                                {
                                    frame = _webBrowser.Browser.GetMainFrame();
                                }
                                else if (evaluationAction.FrameName.IsRegex.Value)
                                {
                                    foreach (var frameName in _webBrowser.Browser.GetBrowser().GetFrameNames())
                                    {
                                        if (Regex.IsMatch(frameName, evaluationAction.FrameName.Value.Value))
                                        {
                                            frame = _webBrowser.Browser.GetBrowser().GetFrame(frameName);
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    frame = _webBrowser.Browser.GetBrowser().GetFrame(evaluationAction.FrameName.Value.Value);
                                }
                                if (frame == null)
                                {
                                    evaluationAction.Success  = false;
                                    evaluationAction.Response = new JavascriptResponse()
                                    {
                                        Message = "Frame not found",
                                        Result  = false,
                                        Success = false,
                                    };
                                    evaluationAction.Completed = true;
                                    break;
                                }
                                JavascriptResponse result =
                                    await
                                    frame.EvaluateScriptAsync(evaluationAction.Script,
                                                              timeout: evaluationAction.Timeout);
                                if (!result.Success)
                                {
                                    if (HandleJavascriptEvaluateResultMessage(result.Message, ref frame,
                                                                              evaluationAction.FrameName.Value.Value))
                                    {
                                        continue;
                                    }
                                    else
                                    {
                                        evaluationAction.Success = false;
                                    }
                                }
                                else
                                {
                                    evaluationAction.Success = true;
                                }
                                evaluationAction.Response  = result;
                                evaluationAction.Completed = true;
                                break;
                            }
                        });
                }
                break;

                case GatewayAction.GatewayActionType.GetHttpAuth:
                {
                    GatewayAction.GetHttpAuth getHttpAuth = (GatewayAction.GetHttpAuth)action;
                    bool     success      = false;
                    HttpAuth removingAuth = null;
                    foreach (var handledHttpAuth in _webBrowser.RequestHandler.HandledHttpAuths)
                    {
                        if (getHttpAuth.ExpectedHost.Value.Value == "" ||
                            (getHttpAuth.ExpectedHost.IsRegex.Value &&
                             Regex.IsMatch(handledHttpAuth.Host, getHttpAuth.ExpectedHost.Value.Value) ||
                             !getHttpAuth.ExpectedHost.IsRegex.Value &&
                             handledHttpAuth.Host == getHttpAuth.ExpectedHost.Value.Value))
                        {
                            if (getHttpAuth.ExpectedRealm.Value.Value == "" ||
                                (getHttpAuth.ExpectedRealm.IsRegex.Value &&
                                 Regex.IsMatch(handledHttpAuth.Realm, getHttpAuth.ExpectedRealm.Value.Value) ||
                                 !getHttpAuth.ExpectedRealm.IsRegex.Value &&
                                 handledHttpAuth.Realm == getHttpAuth.ExpectedRealm.Value.Value))
                            {
                                if (getHttpAuth.ExpectedSchemaType == GetHttpAuth.SchemaTypes.Nope ||
                                    (getHttpAuth.ExpectedSchemaType.ToString() == handledHttpAuth.Scheme.ToString()))
                                {
                                    if (getHttpAuth.ExpectedPort == null ||
                                        ((int)getHttpAuth.ExpectedPort == handledHttpAuth.Port))
                                    {
                                        success           = handledHttpAuth.SuccessfullyHandled;
                                        getHttpAuth.Host  = handledHttpAuth.Host;
                                        getHttpAuth.Port  = handledHttpAuth.Port;
                                        getHttpAuth.Realm = handledHttpAuth.Realm;
                                        foreach (var value in Enum.GetValues(typeof(GetHttpAuth.SchemaTypes)))
                                        {
                                            if (value.ToString() == handledHttpAuth.Scheme)
                                            {
                                                getHttpAuth.Scheme = (GetHttpAuth.SchemaTypes)Enum.Parse(typeof(GetHttpAuth.SchemaTypes), value.ToString());
                                                break;
                                            }
                                        }
                                        removingAuth = handledHttpAuth;
                                    }
                                }
                            }
                        }
                    }
                    if (removingAuth != null)
                    {
                        _webBrowser.RequestHandler.HandledHttpAuths.Remove(removingAuth);
                    }
                    getHttpAuth.Success   = success;
                    getHttpAuth.Completed = true;
                }
                break;

                case GatewayAction.GatewayActionType.SetHttpAuth:
                {
                    GatewayAction.SetHttpAuth httpAuth = (GatewayAction.SetHttpAuth)action;
                    _webBrowser.RequestHandler.PreparedHttpAuths.Add(httpAuth);
                    action.Success   = true;
                    action.Completed = true;
                }
                break;

                case GatewayAction.GatewayActionType.GetJsDialog:
                {
                    GatewayAction.GetJsDialog jsAction = (GatewayAction.GetJsDialog)action;
                    bool     success          = false;
                    JsDialog removingJsDialog = null;
                    foreach (var handledJsDialog in _webBrowser.JsDialogHandler.HandledJsDialogs)
                    {
                        if (jsAction.ExpectedDefaultPromptValue == null ||
                            (jsAction.ExpectedDefaultPromptValue.IsRegex.Value &&
                             Regex.IsMatch(handledJsDialog.DefaultPromptText, jsAction.ExpectedDefaultPromptValue.Value.Value) ||
                             !jsAction.ExpectedDefaultPromptValue.IsRegex.Value &&
                             handledJsDialog.DefaultPromptText == jsAction.ExpectedDefaultPromptValue.Value.Value))
                        {
                            if (jsAction.ExpectedMessageText == null ||
                                (jsAction.ExpectedMessageText.IsRegex.Value &&
                                 Regex.IsMatch(handledJsDialog.MessageText, jsAction.ExpectedMessageText.Value.Value) ||
                                 !jsAction.ExpectedMessageText.IsRegex.Value &&
                                 handledJsDialog.MessageText == jsAction.ExpectedMessageText.Value.Value))
                            {
                                if (jsAction.ExpectedDialogType == GetJsPrompt.DialogTypes.Nope ||
                                    (jsAction.ExpectedDialogType.ToString() == handledJsDialog.DialogType.ToString()))
                                {
                                    success = handledJsDialog.SucessfullyHandled;
                                    jsAction.MessageText        = handledJsDialog.MessageText;
                                    jsAction.DefaultPromptValue = handledJsDialog.DefaultPromptText;
                                    foreach (var value in Enum.GetValues(typeof(GetJsPrompt.DialogTypes)))
                                    {
                                        if (value.ToString() == handledJsDialog.DialogType.ToString())
                                        {
                                            jsAction.DialogType = (GetJsPrompt.DialogTypes)Enum.Parse(typeof(GetJsPrompt.DialogTypes), value.ToString());
                                            break;
                                        }
                                    }
                                    removingJsDialog = handledJsDialog;
                                }
                            }
                        }
                    }
                    if (removingJsDialog != null)
                    {
                        _webBrowser.JsDialogHandler.HandledJsDialogs.Remove(removingJsDialog);
                    }
                    jsAction.Success   = success;
                    jsAction.Completed = true;
                }
                break;

                case GatewayAction.GatewayActionType.SetJsDialog:
                {
                    GatewayAction.SetJsDialog jsAction = (GatewayAction.SetJsDialog)action;
                    _webBrowser.JsDialogHandler.PreparedDialogActions.Add(jsAction);
                    action.Success   = true;
                    action.Completed = true;
                }
                break;

                case GatewayAction.GatewayActionType.ExecuteJavascript:
                {
                    GatewayAction.ExecuteJavascript executeJavascript = (GatewayAction.ExecuteJavascript)action;
                    _webBrowser.Dispatcher.Invoke(() =>
                        {
                            IFrame frame = null;
                            if (executeJavascript.FrameName == null)
                            {
                                frame = _webBrowser.Browser.GetMainFrame();
                            }
                            else if (executeJavascript.FrameName.IsRegex.Value)
                            {
                                foreach (var frameName in _webBrowser.Browser.GetBrowser().GetFrameNames())
                                {
                                    if (Regex.IsMatch(frameName, executeJavascript.FrameName.Value.Value))
                                    {
                                        frame = _webBrowser.Browser.GetBrowser().GetFrame(frameName);
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                frame = _webBrowser.Browser.GetBrowser().GetFrame(executeJavascript.FrameName.Value.Value);
                            }
                            if (frame == null)
                            {
                                executeJavascript.Success = false;
                            }
                            else
                            {
                                frame.ExecuteJavaScriptAsync(executeJavascript.Script);

                                executeJavascript.Success = true;
                            }
                            executeJavascript.Completed = true;
                        });
                }
                break;

                case GatewayAction.GatewayActionType.GetSize:
                {
                    GatewayAction.GetSize getSize = (GatewayAction.GetSize)action;
                    _webBrowser.Dispatcher.Invoke(() =>
                        {
                            getSize.Width  = (int)_webBrowser.ActualWidth;
                            getSize.Height = (int)_webBrowser.ActualHeight;
                        });
                    getSize.Success   = true;
                    getSize.Completed = true;
                }
                break;

                case GatewayAction.GatewayActionType.IsBrowserInitiated:
                {
                    GatewayAction.IsBrowserInitiated initiatedAction = (GatewayAction.IsBrowserInitiated)action;
                    _webBrowser.Dispatcher.Invoke(() =>
                        {
                            initiatedAction.Result = _webBrowser.Browser.IsBrowserInitialized;
                        });
                    initiatedAction.Completed = true;
                }
                break;

                case GatewayAction.GatewayActionType.SendKeyBoard:
                {
                }
                break;

                case GatewayAction.GatewayActionType.SendMouseClick:
                {
                }
                break;

                case GatewayAction.GatewayActionType.SendMouseWheel:
                {
                    var mouseAction = (GatewayAction.SendMouseWheel)action;
                    _webBrowser.Dispatcher.Invoke(() =>
                        {
                            //_webBrowser.Browser.SendMouseWheelEvent();
                            //_webBrowser.Browser.SendMouseWheelEvent((int)mouseAction.WhellLocation.X, (int)mouseAction.WhellLocation.Y, mouseAction.DeltaWheelAction.Key, -mouseAction.DeltaWheelAction.ExpectedValue, CefEventFlags.None);
                            if (mouseAction.DeltaWheelAction.Key != 0)
                            {
                                _webBrowser.Browser.SendMouseWheelEvent((int)(mouseAction.WhellLocation.X), (int)(mouseAction.WhellLocation.Y), (int)(-mouseAction.DeltaWheelAction.Key * _internalZoomLevel), 0, CefEventFlags.None);
                            }
                            else
                            {
                                _webBrowser.Browser.SendMouseWheelEvent((int)(mouseAction.WhellLocation.X), (int)(mouseAction.WhellLocation.Y), 0, (int)(-mouseAction.DeltaWheelAction.Value * _internalZoomLevel), CefEventFlags.None);
                            }
                            //MessageBox.Show(_webBrowser, _webBrowser.Browser.ZoomLevel.ToString());
                        });
                    DrawPoint((int)(mouseAction.WhellLocation.X), (int)(mouseAction.WhellLocation.Y));
                    mouseAction.Success   = true;
                    mouseAction.Completed = true;
                }
                break;

                case GatewayAction.GatewayActionType.SiteLoaded:
                {
                    var site = (GatewayAction.SiteLoaded)action;
                    _webBrowser.Dispatcher.Invoke(() =>
                        {
                            site.Address = _webBrowser.Browser.Address;
                            site.Success = !_webBrowser.Browser.IsLoading;
                        });
                    site.Completed = true;
                }
                break;

                case GatewayAction.GatewayActionType.ResourceLoaded:
                {
                    var resource = (GatewayAction.ResourceLoaded)action;
                    _webBrowser.Dispatcher.Invoke(() =>
                        {
                            foreach (var loadedResource in _webBrowser.RequestHandler.LoadedResources
                                     )
                            {
                                if (resource.FrameName == null && loadedResource.IsMainFrame ||
                                    resource.FrameName != null &&
                                    (resource.FrameName.IsRegex.Value
                                        ? Regex.IsMatch(loadedResource.FrameName, resource.FrameName.Value.Value)
                                        : loadedResource.FrameName == resource.FrameName.Value.Value))
                                {
                                    if (resource.ResourceUrl.IsRegex.Value
                                        ? Regex.IsMatch(loadedResource.Url, resource.ResourceUrl.Value.Value)
                                        : (loadedResource.Url == resource.ResourceUrl.Value.Value))
                                    {
                                        resource.Success  = true;
                                        resource.DateTime = loadedResource.DateTime;
                                    }
                                }
                            }
                        });
                    resource.Completed = true;
                }
                break;

                case GatewayAction.GatewayActionType.FrameLoaded:
                {
                    var frame = (GatewayAction.FrameLoaded)action;
                    _webBrowser.Dispatcher.Invoke(() =>
                        {
                            List <FrameLoadingState> frameLoadingStates = _webBrowser.BrowsingState.FrameLoadingStates;
                            foreach (FrameLoadingState state in frameLoadingStates)
                            {
                                if (state.IsMainFrame && frame.FrameName == null || frame.FrameName != null &&
                                    (frame.FrameName.IsRegex.Value
                                        ? Regex.IsMatch(state.FrameName, frame.FrameName.Value.Value)
                                        : frame.FrameName != null &&
                                     state.FrameName == frame.FrameName.Value.Value))
                                {
                                    frame.Success = !state.IsLoading;
                                    break;
                                }
                            }
                        });
                    frame.Completed = true;
                }
                break;

                case GatewayAction.GatewayActionType.ShowMessageBox:
                {
                    GatewayAction.ShowMessageBox messageBox = (GatewayAction.ShowMessageBox)action;
                    _webBrowser.Dispatcher.Invoke(() =>
                        {
                            MessageBox.Show(_webBrowser, messageBox.Text);
                        });
                    messageBox.Completed = true;
                }
                break;

                case GatewayAction.GatewayActionType.GetFrameNames:
                {
                    var getFrameNames = (GatewayAction.GetFrameNames)action;
                    _webBrowser.Dispatcher.Invoke(() =>
                        {
                            IFrame mainFrame = _webBrowser.Browser.GetMainFrame();
                            foreach (string frameName in _webBrowser.Browser.GetBrowser().GetFrameNames())
                            {
                                getFrameNames.Frames.Add(frameName, mainFrame.Name == frameName);
                            }
                            getFrameNames.Success = true;
                        });
                    action.Completed = true;
                }
                break;
                }
            }
            _gatewayTimer.Start();
        }