Embeding Firefox Brower (Gecko Engine) in C# using GeckoFX

11:19 PM
Ever Thought if it was possible to not WebBrower control and use the Firefox Browser in your c# window Application...??

Yes ,, It is possible using GeckoFx wrapper class for  C#.net and vb also.

You will need the Followings:

1. GeckoFx Wrapper [Download]
2. Xul Runner [Download] (Download the zip file from here)

How to:

1.   Now Extract Skybound.GeckoFX.bin.v1.9.1.0.zip (First download).
      You will find Skybound.Gecko.dll and that's what we need.
2.   Now create a Project and name is GeckoFxcsharpBorwer or anything you like.
3.   Now  add the reference of the above dll and also add that to your toolbox.
4.   Now Exctract the Second downloaded file (xulrunner-1.9.1.2.en-US.win32.zip). and you will find xulrunner . This is the path to xulrunner runtime.
5.   Create a Form Layout Like The Figure Below:


Now The Coding Part:

Our Form's Constructor:(Providing the Path to XulRunner Runtime)

public Form1()
        {
            InitializeComponent();
            Skybound.Gecko.Xpcom.Initialize("Path To the xulrunner directory [Extracted from the Second Downloaded File]"); // for example "c:\\xulrunner\\"
        }

Form's Load Event:

private void Form1_Load(object sender, EventArgs e)
        {
            geckoWebBrowser1.Navigate("www.google.com");
        }

Stop Button click Event:


private void btnStop_Click(object sender, EventArgs e)
        {
            geckoWebBrowser1.Stop();
        }



Refresh Button Click Event:


private void btnRefresh_Click(object sender, EventArgs e)
        {
            geckoWebBrowser1.Refresh();
        }



Save Page Button Click Event:


private void btnSavePage_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.Filter = " Html File | *.html";
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                geckoWebBrowser1.SaveDocument(sfd.FileName);
            }
        }


And Now Finally the Output:


That's All.

Complete Project : GeckoNet

ps: You can easily Add an Addressbar and other stuff

20 comments:

{ sam } at: June 2, 2011 at 1:14 AM said...

you are welcome :)

{ KyleB } at: July 3, 2012 at 7:56 AM said...

Does this control require running on a STA thread like the web browser control in .net?

{ Unknown } at: September 14, 2012 at 11:42 PM said...

sir can u teach me how to add reference using gecko? like print.always_print_silent, true

{ imholiday } at: December 1, 2012 at 9:00 AM said...

great dude; thank you very much!!!

{ antrampa } at: July 9, 2013 at 2:27 AM said...

Nice work and very nice example !!!

{ Unknown } at: August 2, 2013 at 2:04 AM said...

Thank you it helps me a lott

{ Unknown } at: August 31, 2013 at 1:13 AM said...

i don't see geckoWebBrowser1 . How can i ?

{ Unknown } at: September 1, 2013 at 11:26 AM said...

yes, nice, but really too short ! How can I add the reference to the toolbox ???

{ abhilashblog } at: September 5, 2014 at 2:43 AM said...

How to enable to open new window and popup?

{ sam } at: September 10, 2014 at 10:50 PM said...

@Phillip Bismonte : Adding reference is easy. Find the references in your Visual Studio Solution Explorere. Right click and add Reference. Choose the DLL.

{ sam } at: September 10, 2014 at 10:50 PM said...

@Marco Pagaroli: Adding reference is easy. Find the references in your Visual Studio Solution Explorere. Right click and add Reference. Choose the DLL.

{ sam } at: September 10, 2014 at 11:00 PM said...

For Adding to Toolbox , Right click anywhere on ToolBox panel and select "Choose Items" -> Go to .NET Frame work component -> Browse for the DLL file and you will find the "GeckoWebBrowser" component.

Click OK

{ k } at: September 13, 2014 at 3:07 PM said...

If I run this on another PC it doesnt start, how to fix this issue?

{ pradeep k } at: September 25, 2014 at 11:48 PM said...

How to add inspect element or console.

{ Sunny } at: May 19, 2015 at 11:51 PM said...

Show Error in Program.cs.
"Specified Cast is not valid"
on
Application.Run(new Form1());

{ Rahul Shakya } at: August 4, 2015 at 6:12 AM said...

How to call click event of a button from code?

{ Unknown } at: September 1, 2015 at 6:48 PM said...

thanks sir...can u help me for update fx , this working but i want to upgrade version...if have any opetion please share with all reader....i thing it's help full question all adv programmer

{ Unknown } at: March 26, 2016 at 11:23 PM said...

THIS CODE RUN INTERNET EXPLORER , NOT MOZILA FIREFOX

{ Unknown } at: April 12, 2016 at 4:41 AM said...

This is running internet explorer only, but not firefox. please give me some solution to run fire fox.

{ Unknown } at: March 23, 2018 at 1:03 PM said...


sfd.FileName = "geckoprint";
sfd.InitialDirectory = @"C:\Users\SAURABH\Desktop\applicatio";
sfd.Filter = " Html File | *.html";


if (sfd.ShowDialog() == DialogResult.OK)
{

geckoWebBrowser1.SaveDocument(sfd.FileName);


}

thx for updating this

Post a Comment