0

The situation:
Using VB.NET Framework 3.5 and Visual Studio 2005 i crated a project which uses the WebBrowser object in a working thrat. Breaking it down to the very basics, it looks like:

Dim bWbCompletedDocument As Boolean = False 

Sub WbCompletedDocument(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)
    bWbCompletedDocument = True
End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)Handles Me.Load
    Dim th As New System.Threading.Thread(AddressOf worker)
    th.SetApartmentState(Threading.ApartmentState.STA)
    th.Start()
End Sub

Sub worker()
    Dim Wb As New WebBrowser
    Wb.ScriptErrorsSuppressed = True
    AddHandler Wb.DocumentCompleted, AddressOf WbCompletedDocument

    Wb.Navigate("google.de")

    Dim start As Date = Now

    Do While start.AddSeconds(20) > Now
        Application.DoEvents()
        If (bWbCompletedDocument = True) And (Wb.IsBusy = False) And (Wb.ReadyState = WebBrowserReadyState.Complete) Then
            Exit Do
        End If
    Loop

    If bWbCompletedDocument = False Then
        Exit Sub
    End If

    'more code here

End Sub

There is no GUI of the Browser but everything works fine. I navigate to a page catch the DocumentCompleted-event, check the ReadyState and if he IsBuisy and go on with my code.

The Problem
There are sites which start to execute JavaScript-Code when the onLoad-Event occurs. If I just proceed with my .Net code after the Wb-object has loaded the Page, the Wb stops executing JavaScript.

The Question
Is there a way to determine if there is currently JavaScript running in the WebBrowser-Object and/or to wait for it to finish?

MGmotors
  • 3
  • 2
  • Are you also the owner (can you change) of the webpage/javascript? – Emond May 10 '13 at 08:32
  • No, i'm not the owner. But i should be able to [inject javascript](http://stackoverflow.com/questions/153748/how-to-inject-javascript-in-webbrowser-control)
    Could that help?
    – MGmotors May 10 '13 at 11:06

1 Answers1

0

If you are able to add javascript to the page you could raise an event to signal the .NET application at the correct moment. Or you could set a status in javascript and have the .NET application poll it.

See: How to handle javascript events via WebBrowser control for WinForms

Community
  • 1
  • 1
Emond
  • 50,210
  • 11
  • 84
  • 115