William Anthony
William Anthony

Reputation: 89

How to know if the browser REALLY finished browsing

I'm usually get to know if the browser has finished loading with DocumentCompleted event.

But lately, When I'm trying site like http://youtube.com, the documentcompleted event is firing up more than once. I placed console.writeline to check what's happened

Private Sub mybrowser_Navigating(ByVal sender As Object, ByVal e As Gecko.GeckoNavigatingEventArgs) Handles mybrowser.Navigating
    Console.WriteLine("navigating " + e.Uri.AbsoluteUri)
End Sub

Private Sub mybrowser_Navigated(ByVal sender As Object, ByVal e As Gecko.GeckoNavigatedEventArgs) Handles mybrowser.Navigated
    Console.WriteLine("navigated " + e.Uri.AbsoluteUri)
End Sub

Private Sub mybrowser_DocumentCompleted(ByVal sender As Object, ByVal e As System.EventArgs) Handles mybrowser.DocumentCompleted
    Console.WriteLine("document " + mybrowser.Document.Url.AbsoluteUri)
End Sub

The result is (test with http://youtube.com)

navigating http://youtube.com/
navigated http://www.youtube.com/
document http://www.youtube.com/
navigating http://www.google.com/pagead/drt/ui
navigated wyciwyg://0/http://www.youtube.com/
navigating wyciwyg://0/http://www.youtube.com/
document http://www.youtube.com/
navigating about:blank
document http://www.youtube.com/
document http://www.youtube.com/

As you can see, the site is redirecting and firing up navigating event several time, including cache, google pagead site and about:blank(???). Each navigating event will be ended by documentcompleted event.

So, what event should I listened if I just want to know when the browser REALLY completed browsing the site no matter how many redirect?

Upvotes: 2

Views: 2089

Answers (2)

Jason
Jason

Reputation: 11

Add this event handler and routine in VB.net

Sub PageLoaded_Event(ByVal sender As Object, ByVal e As Gecko.Events.GeckoDocumentCompletedEventArgs) Handles GeckoWebBrowser1.DocumentCompleted
    PageLoaded = True
End Sub

Sub WaitForNav()
    While PageLoaded = False
        Application.DoEvents()
    End While
    PageLoaded = False
End Sub

Then after every geckowebbrowser.navigate(www...) call WaitForNav.

Hope this helps others

Upvotes: 1

Doug
Doug

Reputation: 6442

Not sure about older versions, but in version 12.0 of GeckoFx, there are two useful properties:

  • IsBusy
  • IsAjaxBusy

You can determine if the browser is done loading the document and all the stuff by checking for this two properties:

if (geckofx.IsBusy || geckofx.IsAjaxBusy)
{
    // still busy, not finished yet
}
else
{
    // finished
}

The example is C#, sorry. But you can probably convert it to VB.NET better than I can.

Upvotes: 1

Related Questions