This isn't a patch but one possible solution. I wrote a wrapper for WWW::Mechanize::Chrome in Moose. Note that that get method is overridden. Every 1/10th of a second it checks to see if new elements have been loaded on the page. If there were, it waits another 1/10th of a second. The length of time can be increased for slower connections.

package WWW::Mechanize::Chrome::MooseWrapper ; use Moose; use MooseX::NonMoose; use Time::HiRes qw(usleep); use File::Temp 'tempdir'; use Log::Log4perl qw(:easy); use Data::Dumper qw(Dumper); use namespace::autoclean; extends 'WWW::Mechanize::Chrome'; sub FOREIGNBUILDARGS { my $class = shift; my %args = ( @_ == 1 ? %{ $_[0] } : @_); # set default launch args $args{launch_exe} = $args{launch_exe} || "/Applications/Go +ogle Chrome.app/Contents/MacOS/Google Chrome"; $args{launch_arg} = $args{launch_arg} || [ '--disable-noti +fications' ]; $args{data_directory} = $args{data_directory} || tempdir(); $args{incognito} = exists $args{incognito} ? $args{incognito} +: 1; return %args; } ### Public methods ### sub scroll_to_bottom { my $s = shift; $s->eval( 'window.scroll(0,document.body.scrollHeight)' ); } sub scroll_to_top { my $s = shift; $s->eval( 'window.scroll(0,0)' ); } sub get_element_count { my $s = shift; my ($el_count) = $s->eval( 'document.getElementsByTagName("*").lengt +h' ); return $el_count; } around get => sub { my $orig = shift; my $s = shift; my $url = shift; $s->SUPER::get($url); my $el_count = $s->get_element_count; # wait 1/10th sec for more of the page to load usleep 100000; while ($el_count != $s->get_element_count) { # wait 1/10th sec for more of the page to load usleep 100000; $el_count = $s->get_element_count; } }; ### Private methods ### __PACKAGE__->meta->make_immutable; 1; # Magic true value

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks


In reply to Re^2: Waiting for page to load with WWW::Mechanize::Chrome by nysus
in thread Waiting for page to load with WWW::Mechanize::Chrome by nysus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.