Click here to Skip to main content
11,409,532 members (62,886 online)
Click here to Skip to main content

C#: WebBrowser vs Gecko vs Awesomium vs OpenWebKitSharp: What To Choose And How to Use

, 1 Feb 2015 CPOL
Rate this:
Please Sign up or sign in to vote.
Comparison of 4 browser engines and controls + some tips for using them (in attached projects and in tip text). Short and clear.

Gecko & WebKit samples are under construction now, but are already working and may be used as a good start:

Who is Who?

WebBrowser

  • Default .NET browser engine.
  • Based on MSHTML + Active-X control based on COM IWebBrowser2. MSHTML+IWebBrowser2 are main components of Internet Explorer browser.
  • Has different Winforms and WPF ports.

Gecko

  • Third-party browser engine.
  • Based on XULRunner used in Firefox browser.
  • Has Winforms version only.

Warning! This tip is fully actually only for very, very old Gecko version (1.9). I'll change it to a newer and more powerful version (10.*..29.* probably), a bit later.

Awesomium WebControl

  • Third-party browser control with external customizable core.
  • Based on .NET Awesomium core wrapper based on Awesomium core based on modified Chromium (or WebKit) engine.
  • Has different Winforms, WPF, Mono ports.

OpenWebKitSharp

  • Third-party browser engine.
  • Based on WebKit engine used in Safari and Chromium browsers.
  • Has Winforms version only.

EO.WebBrowser

  • Third-party browser engine.
  • Based on Chromium project.
  • Has Winforms and WPF ports.

Who is Better?

Nobody! Programming language, framework, engine usually may be better only for a particular purpose.

You can define your objectives, weigh the pros and cons of engines listed in the table below, and select the engine, the best for you.

Tip: This tip has an extremely large width. Table can be not placed in browser window. If you use a fixed layout, it's recommended to change it to fluid.
Change it back to fixed.

  WebBrowser Gecko Awesomium OpenWebKitSharp EO.WebBrowser
License Free. Proprietary Free. Open-source: MPL 1.1/GPL 2.0/LGPL 2.1 Free if your revenue up
to $100K (or costs $2900).
Proprietary
Free. Open-source Free trial version with notification ads. Proprietary
OS/Platforms Winforms, WPF Winforms Winforms, WPF Cross-platform:
Unity, Mono, SDL
Winforms. Cross-platform: ? Winforms, WPF
CPU Any CPU ? x86 ? Any CPU
Page loading speed Low Medium (?). Control can freezing the form for few seconds on its create High High High
Required dlls size 0 MB (included in Win) 22.4 MB 40.5 MB 64.6 MB ?
Not freezing GUI
when page loads
No No Yes No Yes, excepts a 1st load
Minimal .NET Version .NET 2.0 or more older .NET 2.0 or more older .NET 4.0 ? ?

Object, method, property model

- WebBrowser-identical Not WebBrowser-identical WebBrowser-identical, but very unfinished, many methods and properties not working! ?
DOM manipulate - set HTML Yes Yes Yes Via Js only ?
DOM manipulate - get HTML Yes Yes Yes, but don't work with
disabled JS! Also, there is a bug, use JS analogue -
document.documentElement.

			outerHTML
Via Js only ?
DOM - GetElementById Yes Yes Via Js only ? ?
DOM - GetElementsByClassName Via Js only Yes Via Js only ? ?
DOM - GetElementsByTagName Yes Yes Via Js only ? ?
Inject + exec / exec Js Inject + exec Yes, in newer versions Exec Exec ?
Disable Js No, only on all-IE level Yes Yes ? ?
Set proxy No, only on all-IE level Yes Yes ? ?
Dev - Built-in Visual HTML Builder Yes ? No No ?
Dev - HTML code syntax-hl viewer No ? Yes Yes ?
Dev - HTML code Visual Inspector & Editor No ? No Yes Yes
Built-in download manager ? ? ? Yes ?

WebBrowser Usage and Tricks

Built-in Visual HTML Editor

How to enable it:

webBrowser1.Document.DomDocument.GetType().GetProperty("designMode").SetValue
    (webBrowser1.Document.DomDocument, "On", null);

How to paste HTML element programmatically:

// appends:
// <a id="mylink" href="http://codeproject.com/">
//   <img id="myimg" 
//    src="http://dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/logo250x135.gif" />
// </a>

var mylink = webBrowser1.Document.CreateElement("a");
mylink.Id = "mylink";
mylink.SetAttribute("href", "http://codeproject.com/");
             
var myimg = webBrowser1.Document.CreateElement("img");
myimg.Id = "myimg";
myimg.SetAttribute("src", 
"http://dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/logo250x135.gif");
mylink.AppendChild(myimg);
webBrowser1.Document.Body.AppendChild(mylink); 

DOM element selection - GetElementById

var id = "mylink";

var el = webBrowser1.Document.GetElementById(id);
if (el != null)
{
    MessageBox.Show("Element with id=\"" + id + "\" has innerHTML: " + el.InnerHtml);
}
else
{
    MessageBox.Show("Element with id=\"" + id + "\" not found.");
}

DOM element selection - GetElementsByTagName

var tag = "img";

var elz = webBrowser1.Document.GetElementsByTagName(tag);
if (elz.Count > 0)
{
    MessageBox.Show(elz.Count + " elements with tag <" + tag + "> found.");
}
else
{
    MessageBox.Show("No elements with tag <" + tag + "> found.");
}

DOM content manipulate - set HTML

webBrowser1.DocumentText = "<html><head><script>alert('check!');
</script></head><body>lorem</body></html>";

Inject + exec Js

var head = webBrowser1.Document.GetElementsByTagName("head")[0];

var scriptEl = webBrowser1.Document.CreateElement("script");
scriptEl.SetAttribute("text", "function sayHello() { alert('hello') }");
head.AppendChild(scriptEl);

webBrowser1.Document.InvokeScript("sayHello");

Gecko Usage and Tricks

DOM content manipulate - set HTML

geckoWebBrowser1.Document.DocumentElement.InnerHtml = 
"<html><head></head><body>
<a class=\"link\">f</a></body></html>";

DOM element selection - GetElementsByClassName

(geckoWebBrowser1.Document.GetElementsByClassName("link")[0] as 
    Skybound.Gecko.GeckoElement).InnerHtml = "tt";

Awesomium WebControl Usage and Tricks

DOM content manipulate - set HTML

webControl1.HTML = "<html><head><script>alert
('check!');</script></head><body>lorem</body></html>";

DOM content manipulate - get HTML

var allhtml = webControl1.ExecuteJavascriptWithResult
    ("document.documentElement.outerHTML");

Exec Js

webControl1.ExecuteJavascript
("document.body.innerHTML += '<i>Hello, World!</i>';");

Disable Js

var ws = WebCore.CreateWebSession(new WebPreferences() { Javascript = true });
webControl1 = new Awesomium.Windows.Forms.WebControl() { WebSession = ws };
this.Controls.Add(webControl1);

Set proxy

var ws = WebCore.CreateWebSession(new WebPreferences() 
{ ProxyConfig = "255.255.255:8080" });
webControl1 = new Awesomium.Windows.Forms.WebControl() { WebSession = ws };
this.Controls.Add(webControl1);

OpenWebKitSharp Usage and Tricks

DOM content manipulate - set HTML

webKitBrowser1.GetScriptManager.EvaluateScript("document.body.innerHTML='';");

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author


Comments and Discussions

 
QuestionOpenWebKitSharp code is missing PinmemberMember 1136557415-Feb-15 10:14 
AnswerRe: OpenWebKitSharp code is missing Pinmembernaxer1425-Feb-15 17:32 
QuestionGeckoFX is actively developed and version 29 works great PinmemberSire4047-Jan-15 5:24 
AnswerRe: GeckoFX is actively developed and version 29 works great PinprofessionalEmiliarge7-Jan-15 10:37 
SuggestionWebBrowser and Proxy PinmemberMarkus Eßmayr7-Jan-15 3:05 
QuestionEO.Webbrowser Pinmemberinclude767-Jan-15 2:46 
GeneralRe: EO.Webbrowser PinmemberGMariakis7-Jan-15 7:22 
AnswerRe: EO.Webbrowser PinprofessionalEmiliarge7-Jan-15 10:40 
GeneralRe: EO.Webbrowser PinmemberMember 1026752328-Jan-15 4:43 
QuestionwebRTC Pinmemberhynsey6-Jan-15 23:32 
AnswerRe: webRTC PinprofessionalEmiliarge7-Jan-15 2:38 
GeneralCoherent UI .Net Pinmembernishantcop5-Jan-15 21:04 
GeneralRe: Coherent UI .Net PinprofessionalEmiliarge6-Jan-15 8:33 
GeneralRe: Coherent UI .Net PinprofessionalEmiliarge6-Jan-15 10:02 
GeneralRe: Coherent UI .Net Pinmembernishantcop12-Jan-15 23:31 
GeneralRe: Coherent UI .Net Pinmembernishantcop13-Jan-15 0:01 
QuestionWhat about 64 bit support? Pinprofessional i0028-Dec-14 4:30 
AnswerRe: What about 64 bit support? PinprofessionalEmiliarge28-Dec-14 6:42 
AnswerRe: What about 64 bit support? PinmemberISanti29-Dec-14 4:29 
QuestionActually, there's a definitive answer to who is better PinprotectorMarc Clifton19-Dec-14 12:45 
AnswerRe: Actually, there's a definitive answer to who is better PinmemberLuka19-Dec-14 14:05 
GeneralRe: Actually, there's a definitive answer to who is better PinprotectorMarc Clifton19-Dec-14 14:40 
AnswerRe: Actually, there's a definitive answer to who is better PinmemberISanti29-Dec-14 4:05 
QuestionPossibility PinprotectorNelek24-Nov-14 22:55 
AnswerRe: Possibility PinmemberEmiliarge24-Nov-14 23:50 
GeneralRe: Possibility PinprotectorNelek25-Nov-14 0:06 
SuggestionShow the differences in a table instead. [modified] PinprotectorSoMad23-Nov-14 11:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150414.5 | Last Updated 1 Feb 2015
Article Copyright 2014 by Emiliarge
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid