Esempio n. 1
0
        public static void GetUrlList(CefFrame cefFrame, string clasName, string cookieName)
        {
            string jsSetElemets2Cookies = (
                "var a1=document.getElementsByClassName('" + clasName + "');var b1='';for(i=0;i<a1.length;i++ ){ b1+=a1[i].href+'|'; } document.cookie='" + cookieName + "='+b1;"
                );

            cefFrame.ExecuteJavaScript(jsSetElemets2Cookies, cefFrame.Url, 0);

            var cookieVisitor = new CefCookieVisitorImpOfGetCookies(cookieName);

            CefCookieManager.Global.VisitAllCookies(cookieVisitor);
        }
Esempio n. 2
0
        public void ExecuteScript(string script)
        {
            CefFrame frame = _browser?.GetMainFrame();

            if (frame == null)
            {
                Logger.Instance.Log.Error("Mainframe is nullt.");
                return;
            }

            frame.ExecuteJavaScript(script, null, 0);
        }
Esempio n. 3
0
        public void ExecuteScript(string frameName, string script)
        {
            CefFrame frame = _browser?.GetFrame(frameName);

            if (frame == null)
            {
                Logger.Instance.Log.Error($"Frame {frameName} does not exist.");
                return;
            }

            frame.ExecuteJavaScript(script, null, 0);
        }
Esempio n. 4
0
        internal void EnsureLoaded(CefFrame frame)
        {
            var view = GetContext(frame);

            if (view != null)
            {
                return;
            }
            var taskCompletionSource = new TaskCompletionSource <IWebView>();

            _TaskCompletionSources.Add(frame.Identifier, taskCompletionSource);
            //run dummy script to load context
            frame.ExecuteJavaScript("(function(){})()", string.Empty, 0);
        }
Esempio n. 5
0
        ///  <summary>
        ///
        ///  </summary>
        ///  <param name="MainCefFrame"></param>
        /// <param name="jscangetvalue">例如 mydoc.getElementsByClassName('warnMsg')[0].innerHTML</param>
        /// <returns></returns>
        public static string GetMsgByJs3(CefFrame MainCefFrame, string jscangetvalue)
        {
            GlobalVar.jsTmpValue = "";

            string js1 = "var dcxbfjhcacfcxz={1};js2csharp('{0}'+dcxbfjhcacfcxz);"
                         .With("statue=ready&method=testmethod&result=", jscangetvalue);

            MainCefFrame.ExecuteJavaScript(GlobalVar.base_js + js1,
                                           MainCefFrame.Url, 0);
            LogManager.WriteLog("默认阻塞,现在等待");
            GlobalVar.IsloadOkAutoResetEvent.WaitOne(TimeSpan.FromMilliseconds(10 * 1000));
            LogManager.WriteLog("阻塞");
            GlobalVar.IsloadOkAutoResetEvent.Reset();
            //CefGlue.Client\SchemeHandler\Js2CsharpRequestResourceHandler.cs(9)

            return(GlobalVar.jsTmpValue);
        }
Esempio n. 6
0
        ///  <summary>
        ///
        ///  </summary>
        ///  <param name="MainCefFrame"></param>
        /// <param name="jscangetvalue">例如 mydoc.getElementsByClassName('warnMsg')[0].innerHTML</param>
        /// <returns></returns>
        public static string GetMsgByJs2(CefFrame MainCefFrame, string jscangetvalue, string encoding)
        {
            GlobalVar.jsTmpValue = "";
            string js_b1 = "if(window.frames.length!=0){mydoc=window.frames[0].document;}else{mydoc=document;}";
            string js1   = js_b1 + "var dcxbfjhcacfcxz={1};js2csharp('{0}'+dcxbfjhcacfcxz);"
                           .With("statue=ready&method=testmethod&encoding={0}&result=".With(encoding), jscangetvalue);

            MainCefFrame.ExecuteJavaScript(GlobalVar.base_js + js1,
                                           MainCefFrame.Url, 0);
            LogManager.WriteLog("默认阻塞,现在等待");
            GlobalVar.IsloadOkAutoResetEvent.WaitOne(TimeSpan.FromMilliseconds(10 * 1000));
            LogManager.WriteLog("阻塞");
            GlobalVar.IsloadOkAutoResetEvent.Reset();
            //CefGlue.Client\SchemeHandler\Js2CsharpRequestResourceHandler.cs(9)

            return(GlobalVar.jsTmpValue);
        }
Esempio n. 7
0
        public void ExecuteJS(string lines)
        {
            CefFrame frame = browser.GetFocusedFrame();
            // main frame
            if (frame.IsMain)
            {
                string base64EncodedCss = "data:text/css;charset=utf-8;base64,";
                base64EncodedCss +=
                    Convert.ToBase64String(Encoding.UTF8.GetBytes(
                        BrowserConfig.BrowserSourceSettings.CSS));

                string script = lines;
                    

                frame.ExecuteJavaScript(script,
                    null, 0);
            }

        }
Esempio n. 8
0
        public void OnLoadEnd(CefBrowser browser, CefFrame frame,
                              int httpStatusCode)
        {
            // main frame
            if (frame.IsMain)
            {
                string base64EncodedCss = "data:text/css;charset=utf-8;base64,";
                base64EncodedCss +=
                    Convert.ToBase64String(Encoding.UTF8.GetBytes(
                                               BrowserConfig.BrowserSourceSettings.CSS));

                string script = ""
                                + "var link = document.createElement('link');"
                                + "link.setAttribute('rel', 'stylesheet');"
                                + "link.setAttribute('type', 'text/css');"
                                + "link.setAttribute('href', '{0}');"
                                + "document.getElementsByTagName('head')[0].appendChild(link);";

                frame.ExecuteJavaScript(String.Format(script, base64EncodedCss),
                                        null, 0);
            }
        }
        public void ExecuteJavaScript(string jscode)
        {
            CefFrame frame = _lifespanHandler.MainBrowser.GetMainFrame();

            frame.ExecuteJavaScript(jscode, frame.Url, 0);
        }
Esempio n. 10
0
 public void ExecuteJs(string js)
 {
     mainFrame.ExecuteJavaScript(js, "", 0);
 }
Esempio n. 11
0
 public static void ExcuteJs(CefFrame cefFrame, string js2run)
 {
     cefFrame.ExecuteJavaScript(js2run, cefFrame.Url, 0);
 }
Esempio n. 12
0
 public static void SetElementValueById(CefFrame cefFrame, string elementid, string elementvalue)
 {
     cefFrame.ExecuteJavaScript(" document.getElementById('{0}').focus();".With(elementid), cefFrame.Url, 0);
     cefFrame.ExecuteJavaScript(" document.getElementById('{0}').value = \"{1}\";".With(elementid, elementvalue), cefFrame.Url, 0);
     cefFrame.ExecuteJavaScript(" document.getElementById('{0}').blur();".With(elementid), cefFrame.Url, 0);
 }