This is a follow up to an earlier problem report of perl crashes when using Win32OLE to automate IE.
The following PERL attempts to automate IE catching NewWindow2 events. It crashes Perl. A similar program in Python runs without error so the basic logic is believed sound. Note the following relevant crash trace when accessing a page with a single popup. ================================================================== navigate to http://www.kephyr.com/popupkillertest/test/test1.html $VAR1 = { 'ie' => bless( {}, 'Win32::OLE' ), 'tle' => '1136482066.13585', 'ts' => '1136482061.98632', 'popupcount' => 0, 'popups' => [], 'name' => 'Main IE' }; ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 0.12 [PropertyChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 0.13 [BeforeNavigate2] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 0.13 [DownloadBegin] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 0.13 [DownloadComplete] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 0.16 [StatusTextChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 0.17 [DownloadBegin] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 0.18 [ProgressChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 0.20 [StatusTextChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 0.27 [ProgressChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 0.48 [PropertyChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 0.49 [PropertyChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 0.49 [PropertyChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 0.49 [PropertyChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 0.50 [StatusTextChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 0.53 [StatusTextChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 0.54 [StatusTextChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 0.55 [StatusTextChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 0.56 [StatusTextChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 0.57 [StatusTextChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 0.58 [StatusTextChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 0.59 [CommandStateChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 0.60 [TitleChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 0.61 [NavigateComplete2] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 0.61 [StatusTextChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 0.64 [StatusTextChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 0.65 [CommandStateChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 0.65 [CommandStateChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 0.67 [CommandStateChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 0.68 [TitleChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 0.72 [ProgressChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 1.17 [ProgressChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 1.67 [ProgressChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 2.18 [ProgressChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 2.68 [ProgressChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 3.18 [ProgressChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 3.68 [ProgressChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 3.75 [BeforeNavigate2] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 3.76 [StatusTextChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 3.77 [ProgressChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 3.87 [PropertyChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 3.87 [PropertyChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 3.87 [PropertyChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 3.87 [PropertyChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 3.89 [StatusTextChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 3.92 [NavigateComplete2] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 3.93 [StatusTextChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 3.94 [ProgressChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 3.95 [ProgressChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 3.95 [DownloadComplete] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 3.98 [DocumentComplete] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 3.98 [StatusTextChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 4.00 [StatusTextChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 4.00 [ProgressChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 4.01 [DocumentComplete] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 4.02 [StatusTextChange] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 4.03 [NewWindow3] ie Win32::OLE=HASH(0x224f0c) 1116128 1116128 4.03 [NewWindow2] self before new window handling $VAR1 = { 'ie' => bless( {}, 'Win32::OLE' ), 'tle' => '1136482080.17175', 'ts' => '1136482076.14019', 'popupcount' => 0, 'popups' => [], 'name' => 'Main IE' }; new ie Win32::OLE=HASH(0x19d7bec) at HWND 460518 self after push $VAR1 = { 'ie' => bless( {}, 'Win32::OLE' ), 'tle' => '1136482080.17175', 'ts' => '1136482076.14019', 'popupcount' => 1, 'popups' => [ 460518 ], 'name' => 'Main IE' }; ie Win32::OLE=HASH(0x19d7bec) Win32::OLE(0.1703) error 0x800401fd: "Object is not connected to server" in METHOD/PROPERTYGET "HWND" at junk8.pl line 89 =========================================================================== Of particular note is that the crash reports trouble on line 89 as part of an IE event service. The incoming event source is 'ie Win32::OLE=HASH(0x19d7bec)' the same as was previously created to service the popup. Code ============================================================================ #!/usr/bin/perl -w # this site has a large number of popup tests # http://www.kephyr.com/popupkillertest/test/index.html # http://www.kephyr.com/popupkillertest/test/test1.html ... 23 use strict; use Data::Dumper; use Win32::OLE qw( EVENTS ); use Time::HiRes qw(gettimeofday); $|=1; # do not buffer sub navto($); # prototype my $ies = {}; # hash of active ie objects, including popup windows # indexed by HWND of underlying ie instance my $popupcnt = 0; # grand total of all pupups encountered # make the main ie thing my $ie = Win32::OLE->new( 'InternetExplorer.Application' ) or die "error"; $ie->{visible} = 1; Win32::OLE->Option( Warn => 3 ); Win32::OLE->WithEvents( $ie, \&ie_events, 'DWebBrowserEvents2' ); my $mainie = {}; $mainie->{name} = 'Main IE'; $mainie->{ie} = $ie; $mainie->{popups} = []; $mainie->{popupcount} = 0; $mainie->{ts} = $mainie->{tle} = gettimeofday; $ies->{$ie->{HWND}} = $mainie; print "self after initialization\n" . Dumper( $mainie ); # causes popup on 1st 2 loads on any day #navto( 'http://www.cnn.com/' ); # no popup print "\n"; print "--------------------------------------------\n"; print "This navigation always works OK\n"; print "--------------------------------------------\n"; navto( 'http://www.google.com/' ); # single popup print "--------------------------------------------\n"; print "This navigation always FAILS\n"; print "--------------------------------------------\n"; navto( 'http://www.kephyr.com/popupkillertest/test/test1.html' ); # two popups navto( 'http://www.gozer.org/mozilla/popup_tester/' ); # no popup navto( 'http://www.whitehouse.gov/' ); print "\n"; print "--------------------------------------------\n"; print "--------------------------------------------\n"; print "Should see this if all is OK\n"; print "--------------------------------------------\n"; print "--------------------------------------------\n"; sub navto($){ my $url = shift; print "navigate to $url\n" . Dumper($mainie); # init navigation stuff $mainie->{popups} = []; $mainie->{popupcount} = 0; $mainie->{ts} = $mainie->{tle} = gettimeofday; $mainie->{ie}->navigate( $url ); while(gettimeofday - $mainie->{ts} < 60){ Win32::OLE->SpinMessageLoop; # check for events last if( gettimeofday - $mainie->{tle} > 10 ); } print Dumper( $mainie ); if( $mainie->{popupcount} > 0 ){ #print "popup from $puie->{locationurl}\n"; } print "done\n"; print "===================================================\n"; } sub ie_events(){ my( $ie, $event, @args ) = @_; print "ie $ie\n"; print "HWND $ie->{HWND}\n"; my $tn = gettimeofday(); # time now my $xie = $ies->{$ie->{HWND}}; # the underlying ie object #print "ie object on event\n"; #print Dumper($xie); $xie->{tle} = $tn; # remember time last event my $te = sprintf '%6.2f', $tn - $xie->{ts}; print "$xie->{ie}->{HWND} $ie->{HWND} $te [$event]\n"; if( $event eq 'NewWindow2' ) { print "self before new window handling\n"; print Dumper($xie); # create an IE for this popup my $ie = Win32::OLE->new( 'InternetExplorer.Application' ) or die( 'could not start IE on allowed NewWindow2' ); print "new ie $ie at HWND $ie->{HWND}\n"; $ie->{visible} = 1; $ie->{registerasbrowser} = 1; my $popupie = {}; $popupie->{name} = "Popup $popupcnt"; $popupie->{ie} = $ie; $popupie->{popups} = []; $popupie->{popupcount} = 0; $popupie->{ts} = $popupie->{tle} = gettimeofday; $ies->{$ie->{HWND}} = $popupie; # put this on the list of popups $xie->{popupcount} += 1; my $xx = $xie->{popups}; push @{$xx}, $ie->{HWND}; # works when push commented out #Win32::OLE->WithEvents($ie, \&popup_ie_events, 'DWebBrowserEvents2' ); Win32::OLE->WithEvents($ie, \&ie_events, 'DWebBrowserEvents2' ); print "self after push\n"; print Dumper($xie); #$args[0]->Put( $ie->{application} ); $args[0]->Put( $ie ); $args[1]->Put( 0 ); } } ============================================================================ Richard Bell 27 Whispering Pines Rd. Sudbury, Ma 01776 HM 978.443.8098 Cell 978.857.6055 [EMAIL PROTECTED]