Add new Microsoft Edge to web browser control?

UPDATE Jan 2021: WebView2 has been released. This enables integration of the Chromium based Edge as a web control. It’s a lot more complicated to use, unfortunately, but a lot more powerful. Works with WinForms or WPF or C++ apps. https://learn.microsoft.com/en-us/microsoft-edge/webview2/ UPDATE May 2018: FINALLY Microsoft has made it easy. https://blogs.windows.com/msedgedev/2018/05/09/modern-webview-winforms-wpf-apps/ For now, the new … Read more

Prevent from displaying of Windows Security window

You need to provide an implementation of IAuthenticate COM interface to the WebBrowser object via IServiceProvider. Your implementation of IAuthenticate::Authenticate will be called when WebBrowser is dealing with a resource requiring Basic or Windows authentication, giving you a chance to supply the proper user name and password. Below is a complete example of how to … Read more

C# WebBrowser Control Proxy

private Uri currentUri; private void Form1_Load(object sender, EventArgs e) { currentUri = new Uri(@”http://www.stackoverflow.com”); HttpWebRequest myRequest = (HttpWebRequest) HttpWebRequest.Create(“http://www.stackoverflow.com”); //WebProxy myProxy = new WebProxy(“208.52.92.160:80”); //myRequest.Proxy = myProxy; HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse(); webBrowser1.DocumentStream = myResponse.GetResponseStream(); webBrowser1.Navigating += new WebBrowserNavigatingEventHandler(webBrowser1_Navigating); } void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e) { if (e.Url.AbsolutePath != “blank”) { currentUri = new Uri(currentUri, e.Url.AbsolutePath); … Read more

How to deactivate “right click” on WPF Webbrowser Control?

Here is the code of a utility class that allows you to deactivate WPF’s WebBrowser context menu. It also allows you to suppress script errors (WPF WebBrowser control – how to supress script errors?) and change IE’s DOCHOSTUIFLAG. Usage sample: public partial class Player : Window { private WebBrowserHostUIHandler _wbHandler; public Player() { InitializeComponent(); … … Read more

How to inject CSS in WebBrowser control?

I didn’t try this myself but since CSS style rules can be included in a document using the <style> tag as in: <html> <head> <style type=”text/css”> h1 {color:red} p {color:blue} </style> </head> you could try giving: HtmlElement head = webBrowser1.Document.GetElementsByTagName(“head”)[0]; HtmlElement styleEl = webBrowser1.Document.CreateElement(“style”); IHTMLStyleElement element = (IHTMLStyleElement)styleEl.DomElement; IHTMLStyleSheetElement styleSheet = element.styleSheet; styleSheet.cssText = @”h1 … Read more

Getting HTML body content in WinForms WebBrowser after body onload event executes

Here is how it can be done, I’ve put some comments inline: private void Form1_Load(object sender, EventArgs e) { bool complete = false; this.webBrowser1.DocumentCompleted += delegate { if (complete) return; complete = true; // DocumentCompleted is fired before window.onload and body.onload this.webBrowser1.Document.Window.AttachEventHandler(“onload”, delegate { // Defer this to make sure all possible onload event handlers … Read more

C# how to wait for a webpage to finish loading before continuing

Try the DocumentCompleted Event: webBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser_DocumentCompleted); void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { webBrowser.Document.GetElementById(“product”).SetAttribute(“value”, product); webBrowser.Document.GetElementById(“version”).SetAttribute(“value”, version); webBrowser.Document.GetElementById(“commit”).InvokeMember(“click”); }

Get ReadyState from WebBrowser control without DoEvents

Below is a basic WinForms app code, illustrating how to wait for the DocumentCompleted event asynchronously, using async/await. It navigates to multiple pages, one after another. Everything is taking place on the main UI thread. Instead of calling this.webBrowser.Navigate(url), it might be simulating a form button click, to trigger a POST-style navigation. The webBrowser.IsBusy async … Read more