Search code examples
.netgeckofx

GeckoFX - donig events if page load is complete ( .NET )


i'm trying to make my geckofx browser wait for page to load "something like DocumentComplete" but i couldn't, im using geckofx 1.9.2 and i guess that's the problem, maybe this version doesn't support DocumentComplete event, that's an example for what i'm trying to do :

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim uAgent As String = "Mozilla/5.0 (Linux; U; Android 2.3.5; en-US; GT-I9100 Build/GINGERBREAD) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 UCBrowser/10.3.0.552 U3/0.8.0 Mobile Safari/534.30"
    Skybound.Gecko.GeckoPreferences.User("general.useragent.override") = uAgent
    GeckoWebBrowser1.Navigate("google.com")

    If GeckoWebBrowser1.DocumentComplete = True Then 
    Messagebox.show("Page Loaded !", "Done")
    End If
End Sub

Solution

  • You can check what is supported by your version of GeckoFX here https://bitbucket.org/geckofx/

    Apart from that, you need to design your code a bit differently. When you initialize and first use the browser, attach event handlers to events.

    As far as I can see in the code of the oldest GeckoFX version, it does support the DocumentCompleted event

        #region public event EventHandler DocumentCompleted
        /// <summary>
        /// Occurs after the browser has finished parsing a new page and updated the <see cref="Document"/> property.
        /// </summary>
        [Category("Navigation"), Description("Occurs after the browser has finished parsing a new page and updated the Document property.")]
        public event EventHandler DocumentCompleted
        {
            add { this.Events.AddHandler(DocumentCompletedEvent, value); }
            remove { this.Events.RemoveHandler(DocumentCompletedEvent, value); }
        }
    

    This means that you can attach a handler to this event and whenever the browser finishes navigation, it will be called. Put the code you want to executed after it loads in the event handler.