/// <summary> /// create browser /// </summary> /// <returns></returns> private static GeckoWebBrowser CreateBrowserInternal() { GeckoWebBrowser browser = new GeckoWebBrowser(); browser.CreateControl(); return(browser); }
public CSLProcessorOutputConsumer(string script_directory, string citations_javascript, BibliographyReadyDelegate brd, object user_argument) { WPFDoEvents.AssertThisCodeIsRunningInTheUIThread(); this.citations_javascript = citations_javascript; this.brd = brd; this.user_argument = user_argument; // Create the browser Logging.Info("Creating web browser for InCite CSL processing"); web_browser = new GeckoWebBrowser(); web_browser.CreateControl(); // Add the name of the script to run script_directory = Path.GetFullPath(Path.Combine(script_directory, @"runengine.html")); script_directory = script_directory.Replace(@"\\", @"\"); script_directory = script_directory.Replace(@"//", @"/"); Uri uri = new Uri(script_directory); Logging.Info("CSLProcessorOutputConsumer is about to browse to {0}", uri); // This is the only way we can communicate from JavaScript to .NET!! web_browser.EnableConsoleMessageNotfication(); web_browser.ConsoleMessage += web_browser_ConsoleMessage; // Kick off citeproc computation web_browser.Navigate(uri.ToString()); }
public void SpiderMonkeyEntryPointTests() { foreach (var entryPoint in EntryPoints()) { var dummy = new GeckoWebBrowser(); dummy.CreateControl(); var dummyHandle = dummy.Handle; // Try us around the using because, AutoJSContext can throw exception caused by the junk arguments we pass to EntryPoints. try { using (var cx = new AutoJSContext(GlobalJSContextHolder.BackstageJSContext)) { entryPoint.Value(IntPtr.Zero); } } catch (Exception e) { if (e is EntryPointNotFoundException) { Assert.Fail(String.Format("{0} EntryPoint is wrong: {1}", entryPoint.Value, e.Message)); } } dummy.Dispose(); } }
public void SpiderMonkeyEntryPointTests() { foreach (var entryPoint in EntryPoints()) { using (var dummy = new GeckoWebBrowser()) { dummy.CreateControl(); var dummyHandle = dummy.Handle; // Try us around the using because, AutoJSContext can throw exception caused by the junk arguments we pass to EntryPoints. try { using (var cx = new AutoJSContext(dummy.Window)) { entryPoint.Value(cx.ContextPointer, SpiderMonkey.CurrentGlobalOrNull(cx.ContextPointer)); } } catch (Exception e) { if (e is EntryPointNotFoundException) { Assert.Fail(String.Format("{0}:{1} EntryPoint is wrong: {2}", entryPoint.Value, entryPoint.Key, e.Message)); } } } } }
static void Main(string[] args) { if (args.Length != 2) { Console.WriteLine("You need to provide URL and image"); return; } Xpcom.Initialize(@"C:\Libs\xulrunner"); var browser = new GeckoWebBrowser(); browser.CreateControl(); while (!browser.IsHandleCreated) { System.Threading.Thread.Sleep(200); System.Windows.Forms.Application.DoEvents(); } browser.Navigate(args[0]); while (browser.IsBusy) { System.Threading.Thread.Sleep(200); System.Windows.Forms.Application.DoEvents(); } browser.Width = 1044; browser.Height = 768; using (Bitmap bmp = new Bitmap(1024, 768)) { Rectangle rec = new Rectangle(0, 0, 1024, 768); browser.DrawToBitmap(bmp, rec); bmp.Save(args[1]); } browser = null; }
public CSLProcessorOutputConsumer(string script_directory, string citations_javascript, BibliographyReadyDelegate brd, object user_argument) { this.citations_javascript = citations_javascript; this.brd = brd; this.user_argument = user_argument; // Create the browser Logging.Info("Creating web browser"); web_browser = new GeckoWebBrowser(); web_browser.CreateControl(); // Add the name of the script to run script_directory = script_directory + "\\runengine.html"; script_directory = script_directory.Replace("\\\\", "\\"); script_directory = script_directory.Replace("//", "/"); Uri uri = new Uri(script_directory); Logging.Info("CSLProcessorOutputConsumer is about to browse to " + uri); // This is the only way we can communicate from JavaScript to .NET!! web_browser.EnableConsoleMessageNotfication(); web_browser.ConsoleMessage += web_browser_ConsoleMessage; // Kick off citeproc computation web_browser.Navigate(uri.ToString()); }
async void init() { if (!InitFireFoxed) { InitFireFoxed = true; await Task.Run(() => { Thread.Sleep(1000); }); Gecko.Xpcom.Initialize("Firefox"); } this.Title = "Loading..."; this.AllowDrop = true; _gecko = new GeckoWebBrowser(); _gecko.CreateControl(); _gecko.Enabled = false; _gecko.AllowDrop = true; var uri = new Uri(Helper.Config.ServerUrl); //often cookies are stored on domain level, so ".google.com", not "www.google.com" (leading dot is important) string host = uri.Host.Replace("www", ""); CookieManager.Add(host, "/", "WayScriptRemoting", RemotingClient.SessionID, false, false, false, Helper.ConvertDateTimeInt(DateTime.Now.AddYears(3))); //WayScriptRemoting //_gecko.NoDefaultContextMenu = true; //禁用右键菜单 //_gecko.AddMessageEventListener("copyToClipboard", copyToClipboard); //_gecko.AddMessageEventListener("save", save); _gecko.AddMessageEventListener("loadFinish", loadFinish); //_gecko.AddMessageEventListener("watchPointValues", watchPointValues); //_gecko.AddMessageEventListener("openRunMode", openRunMode); //_gecko.AddMessageEventListener("writePointValue", writePointValue); //_gecko.AddMessageEventListener("go", go); //_gecko.AddMessageEventListener("goBack", goBack); //_gecko.AddMessageEventListener("open", open); //_gecko.AddMessageEventListener("openCode", openCode); //_gecko.AddMessageEventListener("fullScreen", fullScreen); //_gecko.AddMessageEventListener("exitFullScreen", exitFullScreen); //_gecko.AddMessageEventListener("showHistoryWindow", showHistoryWindow); winHost.Child = _gecko; _gecko.ProgressChanged += Gecko_ProgressChanged; _gecko.CreateWindow += Gecko_CreateWindow; _gecko.DocumentCompleted += Gecko_DocumentCompleted; if (_dataModel.id != null) { _gecko.Navigate($"{Helper.Config.ServerUrl}/Home/GetWindowContent?windowid={_dataModel.id}"); } else { _gecko.Navigate($"{Helper.Config.ServerUrl}/editor"); } }
public void InitAll() { Xpcom.Initialize(xulrunnerPath); gecko = new GeckoWebBrowser(); gecko.CreateControl(); gecko.NoDefaultContextMenu = true; //禁用右键菜单 gecko.Dock = DockStyle.Fill; panel1.Controls.Add(gecko); gecko.ProgressChanged += Gecko_ProgressChanged; gecko.CreateWindow += Gecko_CreateWindow; gecko.DocumentCompleted += Gecko_DocumentCompleted; //gecko.Navigate("http://echarts.baidu.com"); gecko.Navigate(testUrl); }
/// <summary> /// create browser /// </summary> /// <returns></returns> private static GeckoWebBrowser CreateBrowserInternal() { GeckoWebBrowser browser = new GeckoWebBrowser(); browser.CreateControl(); browser.AddMessageEventListener("__post", ((string data) => { data = System.Web.HttpUtility.UrlDecode(data); })); //////browser.NavigateFinishedNotifier.BlockUntilNavigationFinished(); ////browser.JavascriptError += (sender, error) => ////{ //// // do something ////}; return(browser); }
private GeckoWebBrowser MakeNewBrowser() { Debug.WriteLine("making browser"); var browser = new GeckoWebBrowser(); browser.HandleCreated += new EventHandler(OnBrowser_HandleCreated); browser.CreateControl(); var giveUpTime = DateTime.Now.AddSeconds(2); while (!_browserHandleCreated && DateTime.Now < giveUpTime) { //TODO: could lead to hard to reproduce bugs Application.DoEvents(); Thread.Sleep(100); } return(browser); }
public Form1() { InitializeComponent(); Gecko.Xpcom.Initialize("Firefox"); gecko = new GeckoWebBrowser(); gecko.CreateControl(); gecko.NoDefaultContextMenu = true; //禁用右键菜单 gecko.AddMessageEventListener("copyToClipboard", copyToClipboard); gecko.Dock = DockStyle.Fill; panel1.Controls.Add(gecko); gecko.ProgressChanged += Gecko_ProgressChanged; gecko.CreateWindow += Gecko_CreateWindow; gecko.DocumentCompleted += Gecko_DocumentCompleted; gecko.Navigate("http://localhost:8988/editor"); }
/* private void autocaptcha() * { * GeckoWebBrowser geckoWebBrowser2 = new GeckoWebBrowser(); * * var audiobutton = geckoWebBrowser2.Document.GetElementsByClassName("rc-button goog-inline-block rc-button-audio"); * Gecko.DOM.GeckoButtonElement next = new Gecko.DOM.GeckoButtonElement(audiobutton.ElementAt(1).DomObject); * next.Click(); * }*/ #endregion Browser automation #region Browser events private void geckoWebBrowser1_CreateWindow(object sender, GeckoCreateWindowEventArgs e) { // Full Screen var iframe = geckoWebBrowser1.Document.GetHtmlElementById("aads") as Gecko.GeckoHtmlElement; var close = "data:text/html,<script>self.close()</script>"; GeckoWebBrowser geckoWebBrowser2 = new GeckoWebBrowser(); Rectangle rect = System.Windows.Forms.Screen.GetWorkingArea(this); geckoWebBrowser2.Navigating += new EventHandler <GeckoNavigatingEventArgs>(geckoWebBrowser1_Navigating); geckoWebBrowser2.DocumentCompleted += new EventHandler <GeckoDocumentCompletedEventArgs>(geckoWebBrowser2_DocumentCompleted); geckoWebBrowser2.Dock = DockStyle.Fill; geckoWebBrowser2.CreateControl(); //TabPage tab1 = new TabPage("New WebBrowser"); //tabBrowser.TabPages.Add(tab1); Form2.Controls.Add(geckoWebBrowser2); Form2.CreateControl(); if (list_proxies.Items.Count == 0) { geckoWebBrowser2.Navigate(e.Uri); e.InitialWidth = this.Width; e.InitialHeight = this.Height; } else { Gecko.GeckoPreferences.Default["network.proxy.type"] = 1; Gecko.GeckoPreferences.Default["network.proxy.http"] = proxy[0]; Gecko.GeckoPreferences.Default["network.proxy.http_port"] = Convert.ToInt32(proxy[1]); Gecko.GeckoPreferences.Default["network.proxy.ssl"] = proxy[0]; GeckoPreferences.Default["network.proxy.ssl_port"] = Convert.ToInt32(proxy[1]); GeckoPreferences.Default["network.proxy.remote_dns"] = true; GeckoPreferences.Default["network.proxy.http_remote_dns"] = true; GeckoPreferences.Default["network.proxy.ssl_remote_dns"] = true; Gecko.GeckoPreferences.User["network.proxy.type"] = 1; Gecko.GeckoPreferences.User["network.proxy.http"] = proxy[0]; Gecko.GeckoPreferences.User["network.proxy.http_port"] = Convert.ToInt32(proxy[1]); Gecko.GeckoPreferences.User["network.proxy.ssl"] = proxy[0]; GeckoPreferences.User["network.proxy.ssl_port"] = Convert.ToInt32(proxy[1]); GeckoPreferences.User["network.proxy.remote_dns"] = true; GeckoPreferences.User["network.proxy.http_remote_dns"] = true; GeckoPreferences.User["network.proxy.ssl_remote_dns"] = true; Gecko.GeckoPreferences.Default["browser.cache.disk.enable"] = false; Gecko.GeckoPreferences.User["browser.cache.disk.enable"] = false; GeckoPreferences.User["general.useragent.override"] = agent; geckoWebBrowser2.Navigate(e.Uri); if (iframe != null) { e.InitialWidth = this.Width; e.InitialHeight = this.Height; } else { e.InitialWidth = this.Width; e.InitialHeight = this.Height;; } } }
public void BeforeEachTestSetup() { _gwb = new GeckoWebBrowser(); _gwb.CreateControl(); }
public void BeforeEachTestSetup() { _gwb = new GeckoWebBrowser(); _gwb.CreateControl(); _context = new AutoJSContext(_gwb.Window); }
/// <summary> /// 运行js代码 /// </summary> /// <typeparam name="T">返回值类型</typeparam> /// <param name="jsCode">一段js代码。如:return data.name;</param> /// <param name="data">传到js里面的对象,js可以通过data.*直接使用此参数</param> /// <returns></returns> public T Run <T>(string jsCode, object data) { if (httpServer == null) { throw new Exception("请先调用JsRunner.StartVirtualWebServer启动web服务器"); } var gecko = new GeckoWebBrowser(); gecko.CreateControl(); //加入apicloud.db模拟器 List <ISimulator> simulators = new List <ISimulator>(); foreach (var t in SimulatorTypes) { var obj = (ISimulator)Activator.CreateInstance(t); obj.Init(gecko); simulators.Add(obj); } bool loadFinished = false; gecko.NavigationError += (s, e) => { }; gecko.NSSError += (s, e) => { }; gecko.DocumentCompleted += (s, e) => { loadFinished = true; }; using (System.IO.MemoryStream ms = new MemoryStream()) { System.IO.StreamWriter sw = new StreamWriter(ms, Encoding.UTF8); sw.WriteLine("<!DOCTYPE html>"); sw.WriteLine("<html>"); sw.WriteLine("<body>"); foreach (var simulator in simulators) { simulator.OnWritingScript(sw); } foreach (var path in JsFiles) { if (path[1] == ':') { if (File.Exists(path) == false) { throw new Exception($"文件{path}不存在"); } sw.WriteLine("<script src=\"file:///" + path + "\" type=\"text/javascript\"></script>"); } else { sw.WriteLine("<script src=\"" + path + "\" type=\"text/javascript\"></script>"); } } if (!string.IsNullOrEmpty(this.Html)) { sw.WriteLine(this.Html); } string result; if (_runJsOnWindowLoad) { sw.WriteLine("</body>"); sw.WriteLine("</html>"); sw.Dispose(); var pageid = Guid.NewGuid().ToString("N"); VisitHandler.HtmlContents.TryAdd(pageid, ms.ToArray()); ms.Dispose(); gecko.Navigate($"{ServerUrl}Jack.JSUnitTest?id={pageid}"); while (!loadFinished) { System.Threading.Thread.Sleep(10); System.Windows.Forms.Application.DoEvents(); } var jsContext = new AutoJSContext(gecko.Window); var js = @" (function(d){ var result = (function(data){ try{ " + jsCode + @" } catch(e) { if(typeof e === 'string') return { ______err : e , line:0 }; else { var msg = e.message; if(e.name) msg = e.name + ',' + msg; return { ______err :msg , line:e.lineNumber }; } } })(d); return JSON.stringify(result); })(" + (data == null ? "null" : Newtonsoft.Json.JsonConvert.SerializeObject(data)) + @"); "; jsContext.EvaluateScript(js, out result); jsContext.Dispose(); } else { var guidName = "v" + Guid.NewGuid().ToString("N"); var js = @" <script lang='ja'> var " + guidName + @" = (function(data){ try{ " + jsCode + @" } catch(e) { if(typeof e === 'string') return { ______err : e , line:0 }; else { var msg = e.message; if(e.name) msg = e.name + ',' + msg; return { ______err :msg , line:e.lineNumber }; } } })(" + Newtonsoft.Json.JsonConvert.SerializeObject(data) + @"); " + guidName + @"=JSON.stringify(" + guidName + @"); </script> "; sw.WriteLine(js); sw.WriteLine("</body>"); sw.WriteLine("</html>"); sw.Dispose(); var pageid = Guid.NewGuid().ToString("N"); VisitHandler.HtmlContents.TryAdd(pageid, ms.ToArray()); ms.Dispose(); gecko.Navigate($"{ServerUrl}Jack.JSUnitTest?id={pageid}"); while (!loadFinished) { System.Threading.Thread.Sleep(10); System.Windows.Forms.Application.DoEvents(); } var jsContext = new AutoJSContext(gecko.Window); js = guidName; jsContext.EvaluateScript(js, out result); jsContext.Dispose(); } gecko.Dispose(); if (result.StartsWith("{\"______err\":")) { var errObj = Newtonsoft.Json.JsonConvert.DeserializeObject <Newtonsoft.Json.Linq.JObject>(result); string errMsg = errObj.Value <string>("______err"); //int lineNumber = errObj.Value<int>("line") - 3; throw new Exception(errMsg); } if (result.StartsWith("\"") == false && typeof(T) == typeof(string)) { return((T)(object)result); } if (result == "undefined") { return(default(T)); } return(Newtonsoft.Json.JsonConvert.DeserializeObject <T>(result)); } }