puff has asked for the wisdom of the Perl Monks concerning the following question:

Fellow monks I’m working on a class to automate IE. As part of that automation I need to support popups (NewWindows). I’ve encountered a problem that crashes PERL and have isolated it in the following code. Curiously, if the push that attempts to save the created IE's is commented out the code does NOT CRASH. I’m not sure why. Does anyone have any clues? Does the code work OK elsewhere? I’m completely mystified and uncertain where to look next.

YOU MUST DISABLE ALL POPUP BLOCKERS to test this code.

Slightly updated version of code (a bit easier to read).
#!/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); my $self = {}; my $ie = Win32::OLE->new( 'InternetExplorer.Application' ) or die "error"; $ie->{visible} = 1; Win32::OLE->WithEvents( $ie, \&ie_events, 'DWebBrowserEvents2' ); $self->{ie} = $ie; $self->{popups} = []; $self->{ts} = $self->{tle} = gettimeofday; print "self after initialization\n" . Dumper( $self ); $|=1; # do not buffer sub navto($); # causes popup on 1st 2 loads #navto( 'http://www.cnn.com/' ); # no popup navto( 'http://www.google.com/' ); # single popup 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; @{$self->{popups}} = (); $self->{ts} = $self->{tle} = gettimeofday; print "\n===================================================\n"; print "navigate to $url\n" . Dumper($self); $ie->navigate( $url ); while(gettimeofday - $self->{ts} < 60){ Win32::OLE->SpinMessageLoop; # check for events last if( gettimeofday - $self->{tle} > 10 ); } print "done $url\n" . Dumper( $self ); } sub ie_events(){ my( $ie, $event, @args ) = @_; my $tn = gettimeofday(); $self->{tle} = $tn; my $te = sprintf '%6.2f', $tn - $self->{ts}; print "$self $ie $te [$event]\n"; if( $event eq 'NewWindow2' ) { print "self before new window handling\n"; print Dumper($self); my $popupself = {}; my $ie = Win32::OLE->new( 'InternetExplorer.Application' ) or die( 'could not start IE on allowed NewWindow2' ); print "self after new IE application\n"; print Dumper($self); $popupself->{ie} = $ie; my $xx = $self->{popups}; push @{$xx}, $popupself; #works when commented out print "self after push\n"; print Dumper($self); #$args[0]->Put( $ie->{application}); $args[0]->Put( $ie ); $args[1]->Put( 0 ); } }

Replies are listed 'Best First'.
Re: perl crash, Win32::OLE
by diotalevi (Canon) on Dec 29, 2005 at 19:31 UTC

    While using Win32::OLE with COM objects from Lotus Domino, I also had some exceptions after a certain amount of work had been performed. Perhaps it is a Win32::OLE problem and somewhere in its C code.

    Also, I hope you mean that you're patching Win32::IE::Mechanize which is like WWW::Mechanize but uses IE over Win32::OLE. If not, your class is already written.

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

      I also experiece crashes/hangs (non-reproduceable) after some time. But this is different. It occurs EVERY time without exception. I've sent a note to Jan Dubois (Win32::OLE) to let him know since the odd crash has been an ongoing issue.

      As to IE::Mechanize, I'm working with Abe Timmerman to provide an IE agent that has better page complete logic and deals with NewWindows. Thus this issue.
Re: perl crash, Win32::OLE
by kwaping (Priest) on Dec 29, 2005 at 19:17 UTC
    Are there any error messages?
      Just a modal window associated with a dump. It is headed:

      Perl Command Line Interpreter has encountered a problem and needs to close. We are sorry for the inconvenience.

        Are you using ActiveState Perl, or their Komodo debugger? I an forever getting that message when I use those two together. I've never been able to isolate the cause - when I make changes, the problem usually goes away. I think it's a bug in ActiveState's software, and not in a module, though I can't prove this.

Re: perl crash, Win32::OLE
by pKai (Priest) on Dec 29, 2005 at 19:34 UTC
    That code runs without problems for me: WinXPpro SP2 + IE 6.0.2900.2180.... with
    D:\temp>perl -v This is perl, v5.8.6 built for MSWin32-x86-multi-thread (with 3 registered patches, see perl -V for more detail) Copyright 1987-2004, Larry Wall Binary build 811 provided by ActiveState Corp. http://www.ActiveState. +com ActiveState is a division of Sophos. Built Dec 13 2004 09:52:01
    The popup is blocked by IE.
      Thanks. I should have mentioned that you MUST DISABLE ALL POPUP BLOCKING.