[How to] Block specific Websites with GeckoFX in C#

Have you ever heard of WebBrowser in .NET Application? If yes, then you know how bad is the Default WebBrowser in .NET. In Internet we can find many alternative for the .NET's Default WebBrowser. There are many, such as CefSharp or GeckoFX,....

In this post I will introduce to you GeckoFX and I will show you how to build your first Gecko Browser program with the Blocking Feature.

GeckoFX is the open source component to embedding the Gecko rendering engine from Mozilla Firefox to .NET application.

To download GeckoFX-Source (current version is GeckoFX-45) go to the GeckoFX BitBucket Wikipage https://bitbucket.org/geckofx/geckofx-45.0/wiki/Home

Or we can use "NuGet-Package Manager" to install GeckoFX-45 to your project as the picture below:

NuGet install GeckoFX


After that we'll see the Firefox folder and the 2 new Dependencies in the Project Explorer Window:

Firefox GeckoFX Project explorer

First we have to declare Gecko namespace
using Gecko;

Just one more setting, select all files from the Firefox folder and select "Always copy" or "Copy when newer" to "Output folder" as below:

Copy dll files to Output folder


Now we can use the GeckoWebbrowser. Just declare the GeckoWebBrowser variable and load all the needed dll files as the picture below:

Init GeckoFX - Declare GeckoWebBrowser variable


What is function InitBrowser? It a function to configure the WebBrowser and to add the Browser into the Form

Configure GeckoWebBrowser


The important Thing to use Blocking feature of GeckoFX is we have to enable HttpActivityObserver, so we set here UseHttpActivityObserver = true.

After UseHttpActivityObserver is enabled, we need to add a Event-Handler, in this case is ObserveHttpModifyRequest-Event from GeckoWebBrowser.

When the WebBrowser send any request to any URL the event ObserveHttpModifyRequest will be fired. We can get the URL of the request by using variable request and convert it to string with request.Uri.ToString(). In this example, I block all the Request that contain "google.com" in the URL.

Here is the code:
        public GeckoWebBrowser webBrowser;
        public Form1()
        {
            InitializeComponent();
            Xpcom.Initialize("Firefox"); // Init all Gecko DLL files in the Firefox folder inside the Project
            InitBrowser();
        }

        // Init Browser
        void InitBrowser()
        {
            webBrowser = new GeckoWebBrowser { Dock = DockStyle.Fill, // Fill all the Form
                UseHttpActivityObserver = true // This is to enable HttpActivityObserver
            };
            webBrowser.ObserveHttpModifyRequest += (obj, request) => {
                if (!request.Uri.ToString().Contains("google.com")) // if the request URL contains string "google.com"
                {
                    request.Cancel = true; // Cancel the request to the URL
                }
            };
            this.Controls.Add(webBrowser);
        }
When you have any question, feel free to leave a commend, I will answer as soon as I can. Have fun coding!

P/S: In this tutorial I installed and use GeckoFX-45 32 bit, so when build the project I have to choose x32 Platform (It will give error when you try to compile to 64 bit Application, in case you want to build 64 bit Application, just install GeckoFx45.64 in the NuGet-Package Manager)

[TUT] Làm sao để xóa laban.vn ra khỏi máy tính, trình duyệt internet của bạn

la bàn.vn
Laban.vn là gì ? 
Vâng laban.vn thực chất chỉ là một danh bạ website, tương tự như một cái la bàn khi bạn vào rừng, thế thôi.
Để thực hiện việc gỡ bỏ laban.vn ra khỏi máy tính, trình duyệt của bạn một cách tận gốc. Bạn cần làm theo các bước sau:
Bước 1
  • Với Windows XP: nhấn tổ hợp phím Windows+R Nhập vào:
%SystemDrive%\Documents and Settings\%username%\Application Data
  • Với Windows Vista/7/8: nhấn tổ hợp phím Windows+R Nhập vào:
%SystemDrive%\Users\%username%\AppData\Roaming
Hoặc đơn giản hơn là:
%appdata%
ENTER....
Sau đó xóa 02 file có biểu tượng La Bàn, xong thì đến bước 2 nhé !
Bước 2: Tiếp theo bạn vào Startup xóa chức năng tự khởi động bằng cách:
Nhấn tổ hợp phím Windows+R để mở hộp thoại Run

A lot of horrific scenes after pressing mysterious button

To start promoting quality TV channel TNT in Belgium, this television has put a big red button on the square in quiet Flemish towns.

A curious man who had the courage to press the red button and then, a lot of horrific scenes happen makes people shocked ...


YouTube Easter Egg let's you play Snake while loading Clip (Video)

No, not Metal Gear Solid's Snake. We're talking about the Snake that was popular before the smartphone was a twinkle in the industry's eye. Google has imbued YouTube videos with an engaging new easter egg that lets you play the apple-chasing game while your video stream buffers -- simply mash your keyboard's up and down arrow keys during most any clip to increase YouTube's time-wasting potential tenfold. What's that you say -- your internet connection is so ludicrously fast that videos play instantly? Ah, my lucky friend, let us introduce you to YouTube's 4K mode. Or, for a special treat, hijack the footage we've provided after the break to get your meta-giggles going.

FireFox configuration tricks

Are you a FireFox user?
If YES: 

You may have installed countless add-on in Firefox to enhance your using experience, but if you want to get the most out of Firefox, you really have to hack your way into the about:config.

The about:config page contains most (if not, all) of Firefox configuration options. It is so far the most effective, and the most powerful way to tweak and enhance your Firefox performance. Here are 28 of the popular tweaks.

Accessing your about:config page
In your Firefox, type about:config in the address bar.

Sponsors