The Browser interface provides functionality that allows getting load events. You can attach delegates to get notifications about web page loading progress, document availability, loading failure events, etc. 


Each of these events can be fired for any frame on the web page  during loading the contents.

The list of load events you can receive is the following:


  • StartLoadingFrameEvent - An event that indicates that frame loading process has been started. 
  • FinishLoadingFrameEvent - An event that indicates that frame loading process has been finished.
  • ProvisionalLoadingFrameEvent - An event that indicates that provisional load for a specified frame was successfully committed.
  • FailLoadingFrameEvent - An event that indicates that frame loading process has been failed.
  • DocumentLoadedInFrameEvent- An event that indicates that a frame with a document is loaded.
  • DocumentLoadedInMainFrameEvent - An event that indicates that main frame with a document is loaded.


Example

The following code demonstrates how to receive and handle several load events:

using System;
using DotNetBrowser;
using DotNetBrowser.Events;
namespace MyNamespace
{
    class Program
    {
        static void Main(string[] args)
        {
            ManualResetEvent waitEvent = new ManualResetEvent(false);
            // Create Browser instance.
            Browser browser = BrowserFactory.Create();
            // Register an event that will be fired when web page's frame has been completely loaded.
            browser.FinishLoadingFrameEvent += delegate(object sender, FinishLoadingEventArgs e)
            {
                Console.Out.WriteLine("FinishLoadingFrame: URL = " + e.ValidatedURL + ", IsMainFrame = " + e.IsMainFrame);
                if (e.IsMainFrame)
                {
                    waitEvent.Set();
                }
            };
            // Register an event that will be fired when web page's frame has been started loading.
            browser.StartLoadingFrameEvent += delegate(object sender, StartLoadingArgs e)
            {
                Console.Out.WriteLine("StartLoadingFrame: URL = " + e.ValidatedURL + ", IsMainFrame = " + e.IsMainFrame);
            };
            // Register an event that will be fired when document of main frame has been completely loaded.
            browser.DocumentLoadedInMainFrameEvent += delegate(object sender, LoadEventArgs e)
            {
                Console.Out.WriteLine("DocumentLoadedInMainFrame");
            };
            // Load google.com to get loading events.
            browser.LoadURL("http://www.google.com");
            //Wait until the page is loaded completely.
            waitEvent.WaitOne();
            // Dispose Browser instance.
            browser.Dispose();
        }
    }
}