Click here to Skip to main content
13,199,318 members (44,844 online)
Click here to Skip to main content
Add your own
alternative version

Stats

166.8K views
14.5K downloads
80 bookmarked
Posted 23 Nov 2014

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

, 1 Feb 2015
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.

 WebBrowserGeckoAwesomiumOpenWebKitSharpEO.WebBrowser
LicenseFree. ProprietaryFree. Open-source: MPL 1.1/GPL 2.0/LGPL 2.1Free if your revenue up
to $100K (or costs $2900).
Proprietary
Free. Open-sourceFree trial version with notification ads. Proprietary
OS/PlatformsWinforms, WPFWinformsWinforms, WPF Cross-platform:
Unity, Mono, SDL
Winforms. Cross-platform: ?Winforms, WPF
CPUAny CPU?x86?Any CPU
Page loading speedLowMedium (?). Control can freezing the form for few seconds on its createHighHighHigh
Required dlls size0 MB (included in Win)22.4 MB40.5 MB64.6 MB?
Not freezing GUI
when page loads
NoNoYesNoYes, 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-identicalNot WebBrowser-identicalWebBrowser-identical, but very unfinished, many methods and properties not working!?
DOM manipulate - set HTMLYesYesYesVia Js only?
DOM manipulate - get HTMLYesYesYes, but don't work with
disabled JS! Also, there is a bug, use JS analogue -
document.documentElement.<br />
			outerHTML
Via Js only?
DOM - GetElementByIdYesYesVia Js only??
DOM - GetElementsByClassNameVia Js onlyYesVia Js only??
DOM - GetElementsByTagNameYesYesVia Js only??
Inject + exec / exec JsInject + execYes, in newer versionsExecExec?
Disable JsNo, only on all-IE levelYesYes??
Set proxyNo, only on all-IE levelYesYes??
Dev - Built-in Visual HTML BuilderYes?NoNo?
Dev - HTML code syntax-hl viewerNo?YesYes?
Dev - HTML code Visual Inspector & EditorNo?NoYesYes
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


You may also be interested in...

Pro
Pro

Comments and Discussions

 
QuestionGecko to open pdf files Pin
EyalY9-Jan-17 2:10
memberEyalY9-Jan-17 2:10 
SuggestionAdd CefSharp details Pin
Member 1044748618-Feb-16 23:40
memberMember 1044748618-Feb-16 23:40 
QuestionMultiple profiles Pin
sjc99923-Sep-15 12:55
membersjc99923-Sep-15 12:55 
QuestionCefSharp Pin
Cristanov210-Jul-15 1:20
memberCristanov210-Jul-15 1:20 
QuestionOpenWebKitSharp code is missing Pin
Member 1136557415-Feb-15 9:14
memberMember 1136557415-Feb-15 9:14 
AnswerRe: OpenWebKitSharp code is missing Pin
naxer1425-Feb-15 16:32
membernaxer1425-Feb-15 16:32 
QuestionGeckoFX is actively developed and version 29 works great Pin
Sire4047-Jan-15 4:24
memberSire4047-Jan-15 4:24 
AnswerRe: GeckoFX is actively developed and version 29 works great Pin
Emiliarge7-Jan-15 9:37
professionalEmiliarge7-Jan-15 9:37 
SuggestionWebBrowser and Proxy Pin
Markus Eßmayr7-Jan-15 2:05
memberMarkus Eßmayr7-Jan-15 2:05 
QuestionEO.Webbrowser Pin
include767-Jan-15 1:46
memberinclude767-Jan-15 1:46 
GeneralRe: EO.Webbrowser Pin
GMariakis7-Jan-15 6:22
memberGMariakis7-Jan-15 6:22 
AnswerRe: EO.Webbrowser Pin
Emiliarge7-Jan-15 9:40
professionalEmiliarge7-Jan-15 9:40 
GeneralRe: EO.Webbrowser Pin
Member 1026752328-Jan-15 3:43
memberMember 1026752328-Jan-15 3:43 
QuestionwebRTC Pin
hynsey6-Jan-15 22:32
memberhynsey6-Jan-15 22:32 
AnswerRe: webRTC Pin
Emiliarge7-Jan-15 1:38
professionalEmiliarge7-Jan-15 1:38 
GeneralRe: webRTC Pin
hynsey8-Sep-15 3:14
memberhynsey8-Sep-15 3:14 
GeneralCoherent UI .Net Pin
nishantcop5-Jan-15 20:04
membernishantcop5-Jan-15 20:04 
GeneralRe: Coherent UI .Net Pin
Emiliarge6-Jan-15 7:33
professionalEmiliarge6-Jan-15 7:33 
GeneralRe: Coherent UI .Net Pin
Emiliarge6-Jan-15 9:02
professionalEmiliarge6-Jan-15 9:02 
GeneralRe: Coherent UI .Net Pin
nishantcop12-Jan-15 22:31
membernishantcop12-Jan-15 22:31 
GeneralRe: Coherent UI .Net Pin
nishantcop12-Jan-15 23:01
membernishantcop12-Jan-15 23:01 
QuestionWhat about 64 bit support? Pin
i0028-Dec-14 3:30
professional i0028-Dec-14 3:30 
AnswerRe: What about 64 bit support? Pin
Emiliarge28-Dec-14 5:42
professionalEmiliarge28-Dec-14 5:42 
AnswerRe: What about 64 bit support? Pin
ISanti29-Dec-14 3:29
memberISanti29-Dec-14 3:29 
QuestionActually, there's a definitive answer to who is better Pin
Marc Clifton19-Dec-14 11:45
protectorMarc Clifton19-Dec-14 11:45 

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

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

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