Wednesday, March 05, 2008

Web Page Loading Time in Internet Explorer

Do you know that you can communication with a Windows application via the COM without knowing much details of how COM works. A Tcl extension, tcom, is all you need if you are a Tcl enthusiast like myself. tcom is a Windows-specific Tcl extension that provides commands to access and implement COM objects. It enables client-side and server-side scripting of COM objects through IDispatch and IUnknown derived interfaces. Download ActiveTcl from ActiveState to try out the below example.

Below is a sample script to find out how long it takes for the web page to be completely displayed in Internet Explorer.

package require tcom

set url http://www.your-web-site.com/
set ie [tcom::ref createobject "InternetExplorer.Application"]
$ie Visible 1
$ie Navigate $url
set t1 [clock seconds]
while { 1 } {
 if { [$ie Busy] == 0 } {
  set t2 [clock seconds]
  break
 }
 after 1000
}
$ie Quit
puts "[expr $t2 - $t1] to display $url in Internet Explorer"

You can also find out the complete list of method descriptions for methods defined in the COM interface. Each method description is a list. The first element is the member ID. The second element is the return type. The third element is the method name. The fourth element is a list of parameter descriptions. (extracted from tcom man page).

$ cat tcom.tcl
package require tcom

set ie [tcom::ref createobject "InternetExplorer.Application"]
set interface [tcom::info interface $ie]
foreach i $interface { 
 puts $i
}
$ie Quit


$ ./tcom.tcl
100 VOID GoBack {}
101 VOID GoForward {}
102 VOID GoHome {}
103 VOID GoSearch {}
104 VOID Navigate {{in BSTR URL} {in {VARIANT *} Flags} {in {VARIANT *} TargetFrameName} {in {VARIANT *} PostData} {in {VARIANT *} Headers}}
-550 VOID Refresh {}
105 VOID Refresh2 {{in {VARIANT *} Level}}
106 VOID Stop {}
200 {DISPATCH *} Application {}
201 {DISPATCH *} Parent {}
202 {DISPATCH *} Container {}
203 {DISPATCH *} Document {}
204 {BOOL *} TopLevelContainer {}
205 {BSTR *} Type {}
206 {I4 *} Left {}
206 VOID Left {{in I4 pl} {in {I4 *} propertyValue} {in {I4 *} propertyValue} {in {I4 *} propertyValue}}
207 {I4 *} Top {}
207 VOID Top {{in I4 pl} {in {I4 *} propertyValue} {in {I4 *} propertyValue} {in {I4 *} propertyValue}}
208 {I4 *} Width {}
208 VOID Width {{in I4 pl} {in {I4 *} propertyValue} {in {I4 *} propertyValue} {in {I4 *} propertyValue}}
209 {I4 *} Height {}
209 VOID Height {{in I4 pl} {in {I4 *} propertyValue} {in {I4 *} propertyValue} {in {I4 *} propertyValue}}
210 {BSTR *} LocationName {}
211 {BSTR *} LocationURL {}
212 {BOOL *} Busy {}
300 VOID Quit {}
301 VOID ClientToWindow {{{in out} {INT *} pcx} {{in out} {INT *} pcy}}
302 VOID PutProperty {{in BSTR Property} {in VARIANT vtValue}}
303 {VARIANT *} GetProperty {{in BSTR Property}}
0 {BSTR *} Name {}
-515 {I4 *} HWND {}
400 {BSTR *} FullName {}
401 {BSTR *} Path {}
402 {BOOL *} Visible {}
402 VOID Visible {{in BOOL pBool} {in {BOOL *} propertyValue} {in {BOOL *} propertyValue}}
403 {BOOL *} StatusBar {}
403 VOID StatusBar {{in BOOL pBool} {in {BOOL *} propertyValue} {in {BOOL *} propertyValue}}
404 {BSTR *} StatusText {}
404 VOID StatusText {{in BSTR StatusText} {in {BSTR *} propertyValue} {in {BSTR *} propertyValue}}
405 {INT *} ToolBar {}
405 VOID ToolBar {{in INT Value} {in {INT *} propertyValue} {in {INT *} propertyValue}}
406 {BOOL *} MenuBar {}
406 VOID MenuBar {{in BOOL Value} {in {BOOL *} propertyValue} {in {BOOL *} propertyValue}}
407 {BOOL *} FullScreen {}
407 VOID FullScreen {{in BOOL pbFullScreen} {in {BOOL *} propertyValue} {in {BOOL *} propertyValue}}
500 VOID Navigate2 {{in {VARIANT *} URL} {in {VARIANT *} Flags} {in {VARIANT *} TargetFrameName} {in {VARIANT *} PostData} {in {VARIANT *} Headers}}
501 {I4 *} QueryStatusWB {{in I4 cmdID}}
502 VOID ExecWB {{in I4 cmdID} {in I4 cmdexecopt} {in {VARIANT *} pvaIn} {{in out} {VARIANT *} pvaOut}}
503 VOID ShowBrowserBar {{in {VARIANT *} pvaClsid} {in {VARIANT *} pvarShow} {in {VARIANT *} pvarSize}}
-525 {I4 *} ReadyState {}
550 {BOOL *} Offline {}
550 VOID Offline {{in BOOL pbOffline} {in {BOOL *} propertyValue}}
551 {BOOL *} Silent {}
551 VOID Silent {{in BOOL pbSilent} {in {BOOL *} propertyValue}}
552 {BOOL *} RegisterAsBrowser {}
552 VOID RegisterAsBrowser {{in BOOL pbRegister} {in {BOOL *} propertyValue}}
553 {BOOL *} RegisterAsDropTarget {}
553 VOID RegisterAsDropTarget {{in BOOL pbRegister} {in {BOOL *} propertyValue}}
554 {BOOL *} TheaterMode {}
554 VOID TheaterMode {{in BOOL pbRegister} {in {BOOL *} propertyValue}}
555 {BOOL *} AddressBar {}
555 VOID AddressBar {{in BOOL Value} {in {BOOL *} propertyValue}}
556 {BOOL *} Resizable {}
556 VOID Resizable {{in BOOL Value} {in {BOOL *} propertyValue}}

With such a rich interface, it is possible to traverse a set of URLs or simulate the user's click stream.

Labels: ,

2 Comments:

Blogger Q_CodeGuru_A said...

Hi Chi ..

I executed the PAGE LOAD tcl script on my machine but no load time was displayed instead only a small window of tcl is being displayed.. can you please help me out here..

7:11 PM  
Blogger chihungchan said...

Not sure whether you have the tcom extension installed. I would suggest you install ActiveTcl from ActiveState (http://www.activestate.com/). 8.4 version comes with a lot of precompiled extensions, not sure about 8.5. Download it and try again.

5:15 PM  

Post a Comment

<< Home