public WindowMain() { layout = new Grid(); ColumnDefinition gridCol1 = new ColumnDefinition(); layout.ColumnDefinitions.Add(gridCol1); RowDefinition gridRow1 = new RowDefinition(); gridRow1.Height = new GridLength(45); RowDefinition gridRow2 = new RowDefinition(); layout.RowDefinitions.Add(gridRow1); layout.RowDefinitions.Add(gridRow2); Content = layout; browserView = new WPFBrowserView(BrowserFactory.Create()); Grid.SetRow(browserView, 1); Grid.SetColumn(browserView, 0); muteButton = new Button(); UpdateButtonText(muteButton, browserView.Browser); muteButton.Height = 23; muteButton.Click += muteButton_Click; Grid.SetRow(muteButton, 0); Grid.SetColumn(muteButton, 0); layout.Children.Add(muteButton); layout.Children.Add(browserView); Width = 1024; Height = 768; this.Loaded += WindowMain_Loaded; }
public Form1() { InitializeComponent(); browser = BrowserFactory.Create(); BrowserView browserView = new WinFormsBrowserView(browser); browserView.Browser.DialogHandler = new WinFormsDefaultDialogHandler((Control)browserView.GetComponent()); this.Controls.Add((Control)browserView.GetComponent()); browserView.Browser.FinishLoadingFrameEvent += delegate(object sender, FinishLoadingEventArgs e) { if (e.IsMainFrame) { Browser myBrowser = e.Browser; DOMDocument document = myBrowser.GetDocument(); DOMElement link = document.GetElementById("button"); if (link != null) { link.Click(); } } }; browserView.Browser.LoadHTML("<html><body><button id='button' " + "onclick=\"alert('Button has been clicked!');\">Click Me!</button>" + "</body></html>"); }
public PaypalPmt() { InitializeComponent(); webView = new WPFBrowserView(BrowserFactory.Create()); mainLayout.Children.Add((UIElement)webView.GetComponent()); webView.Browser.LoadURL("http://www.google.com"); }
static void Main(string[] args) { using (Browser browser = BrowserFactory.Create()) { ManualResetEvent waitEvent = new ManualResetEvent(false); // Listen to zoom changed events browser.Context.ZoomService.ZoomChangedEvent += delegate(object sender, ZoomEventArgs e) { Console.Out.WriteLine("e.Url = " + e.Url); Console.Out.WriteLine("e.ZoomLevel = " + e.ZoomLevel); }; browser.FinishLoadingFrameEvent += delegate(object sender, FinishLoadingEventArgs e) { // Wait until main document of the web page is loaded completely. if (e.IsMainFrame) { e.Browser.ZoomLevel = 2.0; waitEvent.Set(); } }; browser.LoadURL("http://www.teamdev.com"); waitEvent.WaitOne(); } }
public WindowMain() { Browser browser = BrowserFactory.Create(); //add custom request handler var customLoadHandler = new CustomLoadHandler(); customLoadHandler.CustomResponseEvent += delegate(object sender, CustomResponseEventArgs e) { if (e.Url.Contains(@"myscheme://test1")) { browser.Stop(); browser.LoadURL(@"http://google.com"); } }; browser.LoadHandler = customLoadHandler; browserView = new WPFBrowserView(browser); Content = browserView; Width = 1024; Height = 768; this.Loaded += WindowMain_Loaded; }
public WindowMain() { Browser browser = BrowserFactory.Create(); browserView = new WPFBrowserView(browser); browser.FinishLoadingFrameEvent += delegate(object sender, FinishLoadingEventArgs e) { if (e.IsMainFrame) { DOMDocument document = e.Browser.GetDocument(); DOMInputElement firstName = (DOMInputElement)document.GetElementByName("firstName"); DOMInputElement lastName = (DOMInputElement)document.GetElementByName("lastName"); DOMInputElement agreement = (DOMInputElement)document.GetElementByName("agreement"); firstName.Value = "John"; lastName.Value = "Doe"; agreement.Checked = true; } }; Content = browserView; Width = 1024; Height = 768; this.Loaded += WindowMain_Loaded; }
public Form1() { InitializeComponent(); browser = BrowserFactory.Create(); BrowserView browserView = new WinFormsBrowserView(browser); browser.DialogHandler = new WinFormsDefaultDialogHandler((Control)browserView); this.Controls.Add((Control)browserView.GetComponent()); browserView.Browser.FinishLoadingFrameEvent += delegate(object sender, FinishLoadingEventArgs e) { if (e.IsMainFrame) { DOMDocument document = e.Browser.GetDocument(); DOMElement link3Element = document.GetElementById("link3"); DOMEventHandler link3Event = delegate(object domEventSender, DOMEventArgs domEventArgs) { if (domEventArgs.Type == DOMEventType.OnFocus) { Console.Out.WriteLine("link3 gets focus"); } if (domEventArgs.Type == DOMEventType.OnBlur) { Console.Out.WriteLine("Remove focus from link3"); } }; link3Element.AddEventListener(DOMEventType.OnFocus | DOMEventType.OnBlur, link3Event, false); DOMElement elementFocused = null; foreach (DOMElement element in document.GetElementsByTagName("a")) { Thread.Sleep(2000); element.Focus(); elementFocused = element; } if (elementFocused != null) { Thread.Sleep(2000); elementFocused.Blur(); } } }; browserView.Browser.LoadHTML(@"<html> <body> <a id='link1' href='#'>The link 1</a> <a id='link2' href='#'>The link 2</a> <a id='link3' href='#'>The link 3</a> <script type='text/javascript'> var link2 = document.getElementById('link2'); link2.addEventListener('focus', function () { console.log('link2 gets focus'); }); link2.addEventListener('blur', function () { console.log('Remove focus from link2'); }); </script> </body> </html>"); }
static void Main(string[] args) { using (Browser browser = BrowserFactory.Create()) { ManualResetEvent waitEvent = new ManualResetEvent(false); browser.FinishLoadingFrameEvent += delegate(object sender, FinishLoadingEventArgs e) { if (e.IsMainFrame) { DOMDocument document = e.Browser.GetDocument(); DOMElement documentElement = document.DocumentElement; // Get the div with id = "root". DOMNode divRoot = documentElement.QuerySelector("#root"); // Get all paragraphs. List <DOMNode> paragraphs = divRoot.QuerySelectorAll("p"); foreach (var paragraph in paragraphs) { Console.Out.WriteLine("paragraph.NodeValue = " + ((DOMElement)paragraph).InnerText); } waitEvent.Set(); } }; browser.LoadHTML( "<html><body><div id='root'>" + "<p>paragraph1</p>" + "<p>paragraph2</p>" + "<p>paragraph3</p>" + "</div></body></html>"); waitEvent.WaitOne(); } }
static void Main(string[] args) { using (Browser browser = BrowserFactory.Create()) { ManualResetEvent waitEvent = new ManualResetEvent(false); browser.FinishLoadingFrameEvent += delegate(object sender, FinishLoadingEventArgs e) { // Wait until main document of the web page is loaded completely. if (e.IsMainFrame) { // Execute JavaScript code and get return value from JavaScript. JSValue returnValue = e.Browser.ExecuteJavaScriptAndReturnValue("document.title"); // Make sure that return value is a string. if (returnValue.IsString()) { // Extract string value from JSValue and write it to Console. Console.Out.WriteLine("The \"document.title\" JavaScript code returns \"" + returnValue.GetString() + "\""); } waitEvent.Set(); } }; browser.LoadURL("http://www.google.com"); waitEvent.WaitOne(); } }
public BrowserForm(string url, int height = 800, int width = 1100, string initialState = "{}") { // InitializeComponent(); this.Height = height; this.Width = width; browser = BrowserFactory.Create(BrowserType.LIGHTWEIGHT); BrowserView = new WinFormsBrowserView(browser); ManualResetEvent waitEvent = new ManualResetEvent(false); BrowserView.DocumentLoadedInMainFrameEvent += delegate (object sender, LoadEventArgs e) { waitEvent.Set(); }; BrowserView.Dock = DockStyle.Fill; Controls.Add(BrowserView); BrowserView.Browser.LoadURL(url); waitEvent.WaitOne(); Del handler = CloseWindow; BrowserView.ScriptContextCreated += delegate (object sender, ScriptContextEventArgs e) { jsStateValue = browser.ExecuteJavaScriptAndReturnValue("window"); jsStateValue.AsObject().SetProperty("UiBrowserState", new UiBrowserState(handler, initialState)); }; // Dispose Browser instance. //BrowserView.Dispose(); }
static void Main(string[] args) { using (Browser browser = BrowserFactory.Create()) { ManualResetEvent waitEvent = new ManualResetEvent(false); browser.FinishLoadingFrameEvent += delegate(object sender, FinishLoadingEventArgs e) { // Wait until main document of the web page is loaded completely. if (e.IsMainFrame) { SearchParams request = new SearchParams("find me"); // Find text from the beginning of the loaded web page. SearchResult result = browser.FindText(request); Console.Out.WriteLine(result.CurrentMatch + "/" + result.NumberOfMatches); // Find the same text again from the currently selected match. result = browser.FindText(request); Console.Out.WriteLine(result.CurrentMatch + "/" + result.NumberOfMatches); waitEvent.Set(); } }; browser.SetSize(700, 500); browser.LoadHTML("<html><body><p>Find me</p><p>Find me</p></body></html>"); waitEvent.WaitOne(); Thread.Sleep(5000); } }
public Form1() { InitializeComponent(); browser = BrowserFactory.Create(); BrowserView browserView = new WinFormsBrowserView(browser); browserView.Browser.DialogHandler = new WinFormsDefaultDialogHandler((Control)browserView.GetComponent()); this.Controls.Add((Control)browserView.GetComponent()); DOMEventHandler domEvent = delegate(object sender, DOMEventArgs e) { DOMEventType eventType = e.Type; Console.Out.WriteLine("handleEvent = " + eventType); }; browserView.Browser.FinishLoadingFrameEvent += delegate(object sender, FinishLoadingEventArgs e) { if (e.IsMainFrame) { DOMDocument document = e.Browser.GetDocument(); DOMElement documentElement = document.DocumentElement; documentElement.AddEventListener(DOMEventType.OnClick | DOMEventType.OnMouseDown | DOMEventType.OnMouseUp | DOMEventType.OnKeyDown, domEvent, false); } }; browserView.Browser.LoadURL("http://www.teamdev.com"); }
static void Main(string[] args) { // Create Browser instance. Browser browser = BrowserFactory.Create(); browser.LoadURL("http://www.google.com"); }
static void Main(string[] args) { Browser browser = BrowserFactory.Create(); JSValue document = browser.ExecuteJavaScriptAndReturnValue("document"); if (document.IsObject()) { // document.title = "New Title" document.AsObject().SetProperty("title", "New Title"); // document.write("Hello World!") JSValue write = document.AsObject().GetProperty("write"); if (write.IsFunction()) { write.AsFunction().Invoke(document.AsObject(), "Hello World!"); } } JSValue documentContent = browser.ExecuteJavaScriptAndReturnValue("document.body.innerText"); if (documentContent.IsString()) { Console.Out.WriteLine("New content: " + documentContent.GetString()); } }
public static Tab CreateTab(String url) { Browser browser = BrowserFactory.Create(BrowserType); BrowserView browserView = new WinFormsBrowserView(browser); browser.DialogHandler = new WinFormsDefaultDialogHandler((Control)browserView); browser.DownloadHandler = new WinFormsDefaultDownloadHandler((Control)browserView); browser.ContextMenuHandler = new WinFormsDefaultContextMenuHandler((Control)browserView, true); browser.Preferences.FireKeyboardEventsEnabled = false; browser.Preferences.FireMouseEventsEnabled = false; TabContent tabContent = new TabContent(browserView); TabCaption tabCaption = new TabCaption(); tabCaption.SetTitle("about:blank"); tabContent.PropertyChangeEvent += delegate(string propertyName, object oldValue, object newValue) { tabCaption.SetTitle(newValue.ToString()); }; browserView.Browser.LoadURL(url); return(new Tab(tabCaption, tabContent)); }
static void Main(string[] args) { using (Browser browser = BrowserFactory.Create()) { //Event for detecting if the page is loaded ManualResetEvent loadedEvent = new ManualResetEvent(false); browser.FinishLoadingFrameEvent += (finishSender, finishArgs) => { if (finishArgs.IsMainFrame) { Console.WriteLine(browser.GetHTML()); loadedEvent.Set(); } }; //Registering the handler for the specified protocol browser.Context.ProtocolService.Register("https", new HttpsHandler()); //Loading Url with the same protocol as registered browser.LoadURL("https://request.url"); //Waiting the page loading loadedEvent.WaitOne(); } Console.ReadKey(); }
static void Main(string[] args) { Browser browser = BrowserFactory.Create(); // Suppress/filter all incoming and outgoing cookies. browser.Context.NetworkService.NetworkDelegate = new MyNetworkDelegate(); }
private void InitBrowser() { try { string path = Assembly.GetExecutingAssembly().Location; string appDir = Path.GetDirectoryName(path); #if DEBUG LoggerProvider.Instance.LoggingEnabled = true; LoggerProvider.Instance.FileLoggingEnabled = true; string logsDir = Path.Combine(appDir, "Logs"); if (!Directory.Exists(logsDir)) { Directory.CreateDirectory(logsDir); } LoggerProvider.Instance.OutputFile = Path.Combine(logsDir, $"DotNetBrowser-{new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Local)}.log"); #endif var uri = new Uri(Path.Combine(appDir, @"PokeEase\index.html")); var browser = BrowserFactory.Create(BrowserType.LIGHTWEIGHT); webView = new WPFBrowserView(browser); browserLayout.Children.Add((UIElement)webView.GetComponent()); webView.Browser.LoadURL(uri.ToString()); } catch { NecroBot.Logic.Logging.Logger.Write("DotNetBrowser has encountered an issue, and has been shut down to prevent a crash", LogLevel.Warning); Settings.Default.BrowserToggled = false; Settings.Default.Save(); BrowserSync(false); } }
protected void OnInitialized() { var switches = DotNetBrowserSwitches.Create(BrowserType); BrowserPreferences.SetChromiumSwitches(switches.ToArray()); _path = GetOrCreateContextParamsPath(); _browserContext = new BrowserContext(new BrowserContextParams(_path)); browser = BrowserFactory.Create(_browserContext, BrowserType); browser.Preferences.AllowDisplayingInsecureContent = false; browser.Preferences.AllowRunningInsecureContent = false; browser.Preferences.AllowScriptsToCloseWindows = false; browser.Preferences.ApplicationCacheEnabled = false; browser.Preferences.DatabasesEnabled = false; browser.Preferences.LocalStorageEnabled = false; browser.Preferences.PluginsEnabled = false; browser.Preferences.TransparentBackground = true; browser.Preferences.UnifiedTextcheckerEnabled = false; browser.Preferences.WebAudioEnabled = false; browser.ZoomEnabled = true; browser.DialogHandler = this; browser.LoadHandler = this; browser.Context.NetworkService.ResourceHandler = this; browser.RenderGoneEvent += Browser_RenderGoneEvent; browser.ScriptContextCreated += Browser_ScriptContextCreated; }
public Form1() { InitializeComponent(); browser = BrowserFactory.Create(); BrowserView browserView = new WinFormsBrowserView(browser); this.Controls.Add((Control)browserView.GetComponent()); browserView.Browser.FinishLoadingFrameEvent += delegate(object sender, FinishLoadingEventArgs e) { if (e.IsMainFrame) { DOMDocument document = e.Browser.GetDocument(); DOMSelectElement select = (DOMSelectElement)document.GetElementById("select-tag"); select.Value = "opel"; } }; browserView.Browser.LoadHTML("<html><body><select id='select-tag'>\n" + " <option value=\"volvo\">Volvo</option>\n" + " <option value=\"saab\">Saab</option>\n" + " <option value=\"opel\">Opel</option>\n" + " <option value=\"audi\">Audi</option>\n" + "</select></body></html>");; }
public Form1() { InitializeComponent(); browserView = new WinFormsBrowserView(BrowserFactory.Create(BrowserType.LIGHTWEIGHT)); Controls.Add((Control)browserView); browserView.Browser.LoadURL("http://www.google.com"); }
public PaypalPmt_Page() { InitializeComponent(); webView = new WPFBrowserView(BrowserFactory.Create()); mainLayout.Children.Add((UIElement)webView.GetComponent()); webView.Browser.LoadURL("http://web.csulb.edu/~phuynh/cecs491b/index.html"); }
public VkPhoneConfirmForm(WebProxy proxy) { InitializeComponent(); BrowserView browser = null; if (proxy != null) { var dataDir = Path.GetFullPath("chromium-data"); var contextParams = new BrowserContextParams(dataDir); var proxyRules = "https=" + proxy.Address.Host + ":" + proxy.Address.Port; contextParams.ProxyConfig = new CustomProxyConfig(proxyRules); browser = new WinFormsBrowserView( BrowserFactory.Create( new BrowserContext(contextParams), BrowserType.LIGHTWEIGHT)); } else { browser = new WinFormsBrowserView(); } wb = (Control)browser; this.Controls.Add(wb); wb.Dock = DockStyle.Fill; browser.Browser.LoadURL("https://vk.com"); }
public WindowMain() { Browser browser = BrowserFactory.Create(); browserView = new WPFBrowserView(browser); browser.FinishLoadingFrameEvent += delegate(object sender, FinishLoadingEventArgs e) { if (e.IsMainFrame) { DOMDocument document = e.Browser.GetDocument(); DOMNode root = document.GetElementById("root"); DOMNode textNode = document.CreateTextNode("Some text"); DOMElement paragraph = document.CreateElement("p"); paragraph.AppendChild(textNode); root.AppendChild(paragraph); } }; Content = browserView; Width = 1024; Height = 768; this.Loaded += WindowMain_Loaded; }
public void Advanced_Search_By_Role_Filters_Results() { using (var driver = BrowserFactory.Create()) { SignInAsAdmin(driver); driver.FindElement(By.PartialLinkText("Users")).Click(); driver.WaitFor(d => d.FindElements(By.CssSelector(".table tbody tr")).Count > 1); driver.FindElement(By.CssSelector(".advanced")).Click(); driver.WaitFor(d => d.FindElements(By.CssSelector(".modal-body")).Count > 0); (driver as IJavaScriptExecutor).ExecuteScript(@"$('select[name=""Role""]').val('Administrator')"); ModalHelper.ClickPrimary(driver); driver.WaitFor(d => d.FindElements(By.CssSelector(".modal-body")).Count == 0); var rows = driver.FindElementsByCssSelector(".table tbody tr"); var filtered = true; foreach (var el in rows) { var td = el.FindElement(By.CssSelector("td:nth-child(3)")); if (td.Text != "Administrator") { filtered = false; } } Assert.IsTrue(filtered); } }
public WindowMain() { BrowserContext browserContext = BrowserContext.DefaultContext; Browser browser = BrowserFactory.Create(browserContext); browser.FinishLoadingFrameEvent += delegate(object sender, FinishLoadingEventArgs e) { if (e.IsMainFrame) { DOMDocument document = browser.GetDocument(); XPathResult result = document.Evaluate("count(//div)"); // If the expression is not a valid XPath expression or the document // element is not available, we'll get an error. if (result.IsError) { Console.WriteLine("Error: " + result.ErrorMessage); return; } // Make sure that result is a number. if (result.IsNumber) { Console.WriteLine("Result: " + result.Number); } } }; browserView = new WPFBrowserView(browser); Content = browserView; Width = 1024; Height = 768; this.Loaded += WindowMain_Loaded; }
private void Init() { browser = BrowserFactory.Create(); browser.Context.NetworkService.ResourceHandler = new AjaxResourceHandler(); browser.Context.NetworkService.NetworkDelegate = new AjaxNetworkDelegate(); browser.LoadURL("https://www.w3schools.com/xml/ajax_examples.asp"); }
public void User_SignIn_Shows_Dashboard() { using (var driver = BrowserFactory.Create()) { SignInAsAdmin(driver); Assert.IsTrue(driver.Url.Contains("Manage/Dashboard")); } }
static void Main(string[] args) { Browser browser = BrowserFactory.Create(); browser.LoadHandler = new SampleLoadHandler(); browser.LoadURL("<https-url-with-invalid-ssl-certificate>"); }
private void AboutDemo() { Form aboutDemo = new Form(); aboutDemo.ShowIcon = false; aboutDemo.Size = new Size(380, 300); aboutDemo.Text = "About Demo"; aboutDemo.FormBorderStyle = FormBorderStyle.FixedDialog; aboutDemo.MaximizeBox = false; aboutDemo.MinimizeBox = false; aboutDemo.StartPosition = FormStartPosition.CenterParent; String strVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(); BrowserView browserView = new WinFormsBrowserView(BrowserFactory.Create(BrowserType.HEAVYWEIGHT)); aboutDemo.Controls.Add((Control)browserView); string textAboutDemo = "<br>" + "<html><font face='Arial' size='2'>" + "<font size='5'>DotNetBrowser Demo</font><br><br>" + "<b>Version " + strVersion + "</b><br><br>" + "<base target='_blank'>" + "This application is created for demonstration purposes only.<br>" + "© 2017 TeamDev Ltd. All rights reserved.<br><br>" + "Powered by <a color='#3d82f8' href='https://www.teamdev.com/dotnetbrowser' " + "style='text-decoration:none'>DotNetBrowser</a>. See " + "<a color='#3d82f8' href='https://www.teamdev.com/dotnetbrowser-licence-agreement' " + "style='text-decoration:none'>terms of use.</a><br>" + "Based on <a color='#3d82f8' href='http://www.chromium.org/' " + "style='text-decoration:none'>Chromium project</a>. " + "See <a color='#3d82f8' " + "href='http://dotnetbrowser-support.teamdev.com/documentation/open-source-components-licences' " + "style='text-decoration:none'>full list</a> of Chromium<br>components, " + "used in the current DotNetBrowser version.<br><br>" + "This demo uses WebKit project under LGPL.<br>" + "See licence text " + "<a color='#3d82f8' href='https://www.gnu.org/licenses/old-licenses/lgpl-2.0.html' " + "style='text-decoration:none'>LGPL v.2</a> and " + "<a color='#3d82f8' href='https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html' " + "style='text-decoration:none'>LGPL v.2.1</a></font></html>"; browserView.Browser.LoadHTML(textAboutDemo); aboutDemo.FormClosing += delegate { if (!browserView.Browser.IsDisposed()) { browserView.Browser.Dispose(); browserView.Dispose(); } }; aboutDemo.ShowDialog(); }