For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic > May 2004 > WebBrowser Control vs InternetExplorer Component









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author WebBrowser Control vs InternetExplorer Component
Salva Maiorano

2004-05-18, 6:30 pm

Hi,
I need to get access to the elements of an open Internet Explorer intance.
But I found that the performance querying the htmlElements is not good at
all.
for some large pages, it takes several seconds to go thru all the elements.
trying to find out how to improve it, I realized that having the same html
page opened in a WebBrowser control (in a VB form) it speed up considerably
the process (but ly, I still need to access an external and existing IE
browser).
my original question was
- how to get quick access to the html elments of an InternetExplorer
instance
and the new one:
- why the huge performance difference accessing thru the WebBrowser control.

I failed trying to find out an answer from Google and from the news.
I really appreciate your answer.
thanks

here is a snapshot of the testing i was doing (that's not real code, just
something quick to prove it)

Option Explicit

Dim IE As SHDocVw.InternetExplorer

Private Sub Form_Load()
Text1.Text = "www.yahoo.com"
End Sub

Sub GetIE(isExternalBrowser As Boolean)
Dim ShellWindows As New SHDocVw.ShellWindows
Dim iIE As SHDocVw.InternetExplorer

Set IE = Nothing
If isExternalBrowser Then
For Each iIE In ShellWindows 'get existing browser, if any
If Not iIE.Name = "Microsoft Internet Explorer" Then
ElseIf iIE.Type = "HTML Document" Then
Set IE = iIE
Exit For
End If
Next
If IE Is Nothing Then Set IE = New SHDocVw.InternetExplorer
Else
Set IE = WebBrowser1
End If
End Sub

Private Sub cmdTest_Click()
TestPerformance True
TestPerformance False
End Sub

Sub TestPerformance(isExternalBrower As Boolean)
Dim TimerIni As Single

GetIE isExternalBrower
IE.Navigate2 Text1.Text
Do
DoEvents
Loop Until Not IE.Busy And IE.document.readyState = "complete"
'wait until the page is loaded

'execute test and timing it
TimerIni = Timer
Debug.Print SomeElmtProcess(IE.document)
Debug.Print "ProcTime (sec) for " & IIf(isExternalBrower, "External ",
"Control ");
Debug.Print Timer - TimerIni
End Sub

Function SomeElmtProcess(doc As HTMLDocument) As String
Dim elmt As IHTMLInputElement
Dim Names As String
Dim repeat As Integer

For repeat = 1 To 100 'just for best measurement
Names = ""
For Each elmt In doc.getElementsByTagName("INPUT")
Names = Names & elmt.Name & ":" & elmt.Value & ", " 'vbNewLine
Next
Next
SomeElmtProcess = Names
End Function

Sub MyHtmlElmtName(doc As HTMLDocument, Names As String)
Dim html As myHtmlDoc
Dim elmt As myHtmlElmt

Set html = New myHtmlDoc
html.Parse doc.documentElement.outerHTML
For Each elmt In html.allElmtsByTag("INPUT")
Names = Names & elmt!Name & vbNewLine
Next
End Sub

Private Sub IE_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, Flags
As Variant, TargetFrameName As Variant, PostData As Variant, Headers As
Variant, Cancel As Boolean)
IEReady = False
End Sub

Private Sub IE_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
IEReady = True
End Sub

Private Sub WebBrowser1_NavigateComplete2(ByVal pDisp As Object, URL As
Variant)
'Stop
End Sub

Private Sub WebBrowser1_NewWindow2(ppDisp As Object, Cancel As Boolean)
'Stop`
'Cancel = True
Dim frm As frmBrowser

Set frm = New frmBrowser
frm.Visible = True
frm.Caption = "Instance " & Forms.Count & ", " &
frm.WebBrowser1.LocationURL
frm.WebBrowser1.Visible = True
Set ppDisp = frm.WebBrowser1.object
End Sub

Private Sub IE_NewWindow(ByVal URL As String, ByVal Flags As Long, ByVal
TargetFrameName As String, PostData As Variant, ByVal Headers As String,
Processed As Boolean)
Stop
End Sub


Private Sub WebBrowser1_OnVisible(ByVal Visible As Boolean)
'Visible = True
End Sub


'Output ->
'ProcTime (sec) for External 4.957031
'ProcTime (sec) for Control 0.01171875




the dude

2004-05-18, 7:30 pm

your instancing a control vs. going through the shell and waiting on ie ( a complete and large app) to reveal it's contents while it also does it's own houskeeping first.

the faster browser control response is also due in part to the control being more lightweight on resources and you have direct control over its behaviour so when you say "give me" it does it when you say (or closer than ie will at least)
Thomas Ganss

2004-05-18, 11:30 pm

Hi,

> - why the huge performance difference accessing thru the WebBrowser

control.
marshalling across process barriers (VB to IE) is more costly
than in-process COM calls (WebBrowser lives in ShDocVw.Dll).

You could create your VB code as a dll to run in IE, then the performance
should be similar to calling WebBrowser elements.

At least you have a start to google or MSDN a bit <g>.

HTH

thomas


Salva Maiorano

2004-05-19, 2:30 am

Tks Thomas.
yes, makes totally sense your point, but it really surprises me the huge
perfromance difference between one method with the another.
s/

"Thomas Ganss" <TGanss_RemoveForRealAdress@T-Online.de> wrote in message
news:c8egmq$d8q$04$1@news.t-online.com...
> Hi,
>
> control.
> marshalling across process barriers (VB to IE) is more costly
> than in-process COM calls (WebBrowser lives in ShDocVw.Dll).
>
> You could create your VB code as a dll to run in IE, then the performance
> should be similar to calling WebBrowser elements.
>
> At least you have a start to google or MSDN a bit <g>.
>
> HTH
>
> thomas
>
>



Salva Maiorano

2004-05-19, 2:30 am

Tks Thomas.
yes, makes totally sense your point, but it really surprises me the huge
perfromance difference between one method with the another.
s/

"Thomas Ganss" <TGanss_RemoveForRealAdress@T-Online.de> wrote in message
news:c8egmq$d8q$04$1@news.t-online.com...
> Hi,
>
> control.
> marshalling across process barriers (VB to IE) is more costly
> than in-process COM calls (WebBrowser lives in ShDocVw.Dll).
>
> You could create your VB code as a dll to run in IE, then the performance
> should be similar to calling WebBrowser elements.
>
> At least you have a start to google or MSDN a bit <g>.
>
> HTH
>
> thomas
>
>



Salva Maiorano

2004-05-19, 2:30 am

Tks Thomas.
yes, makes totally sense your point, but it really surprises me the huge
perfromance difference between one method with the another.
s/

"Thomas Ganss" <TGanss_RemoveForRealAdress@T-Online.de> wrote in message
news:c8egmq$d8q$04$1@news.t-online.com...
> Hi,
>
> control.
> marshalling across process barriers (VB to IE) is more costly
> than in-process COM calls (WebBrowser lives in ShDocVw.Dll).
>
> You could create your VB code as a dll to run in IE, then the performance
> should be similar to calling WebBrowser elements.
>
> At least you have a start to google or MSDN a bit <g>.
>
> HTH
>
> thomas
>
>



Salva Maiorano

2004-05-19, 2:30 am

yes, but at the end, both WebBrowser and InternetExplorer expose the same
HTMLDocument object, which it can be accessed directly, and from where I was
expecting the same behavior, with almost the same performance, independing
from where it is managed.
it's not that i disagree with you, it's just that it really surprises/annoys
me.
tks for your feedback

"the dude" <anonymous@discussions.microsoft.com> wrote in message
news:753A8C03-A129-4179-BD14-039DABDABECD@microsoft.com...
> your instancing a control vs. going through the shell and waiting on ie

( a complete and large app) to reveal it's contents while it also does it's
own houskeeping first.
>
> the faster browser control response is also due in part to the control

being more lightweight on resources and you have direct control over its
behaviour so when you say "give me" it does it when you say (or closer than
ie will at least)


Thomas Ganss

2004-05-19, 5:30 am

Hi Salva,
> but it really surprises me the huge
> perfromance difference between one method with the another.

COM was primarily built to *run* code in shareable objects,
not as an "objectified data container".

Your situation is nearly worst case:
you access properties in a tight loop.
On usual "actions" the COM overhead (even if crossing
process borders) is only a very small %% of the call.

Perhaps you can put the filtered element list
into the vb variable space instead of accessing it
in a loop - been quite a while since I've done vb com processing.

Or create a BHO.

HTH

thomas


Salva Maiorano

2004-05-25, 1:30 pm

thanks Thomas. of course that it helped.


"Thomas Ganss" <TGanss_RemoveForRealAdress@T-Online.de> wrote in message
news:c8f5l6$sp1$00$1@news.t-online.com...
> Hi Salva,
> COM was primarily built to *run* code in shareable objects,
> not as an "objectified data container".
>
> Your situation is nearly worst case:
> you access properties in a tight loop.
> On usual "actions" the COM overhead (even if crossing
> process borders) is only a very small %% of the call.
>
> Perhaps you can put the filtered element list
> into the vb variable space instead of accessing it
> in a loop - been quite a while since I've done vb com processing.
>
> Or create a BHO.
>
> HTH
>
> thomas
>
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com