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

I'm trying to write a script that automates logging into Twitter with WWW::Mechanize::Chrome. The script fills out the user name name and password fields but when it tries to click the "Log in" button, an error is thrown and the browser immediately closes out. The error is:

Didn't see a 'Network.responseReceived' event for frameId CCFEFDAEDAF4 +F4BDFBD57DCF85C5B736, requestId 1000091631.28, cannot synthesize resp +onse at /Users/me/perl5/perlbrew/perls/perl-5.24.1/lib/site_perl/5.24 +.4/WWW/Mechanize/Chrome.pm line 1852.

Here is the script:

#!/usr/bin/env perl use strict; use warnings; use WWW::Mechanize::Chrome; my $mech = WWW::Mechanize::Chrome->new(); $mech->get('http://twitter.com'); $mech->form_number(1); $mech->field('session[username_or_email]' => 'user'); $mech->field('session[password]' => 'password'); $mech->click({ selector => "form.LoginForm input.EdgeButton" });

I've tried different methods for submitting the form but with the same results.

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

Replies are listed 'Best First'.
Re: Unable to automate login to Twitter with WWW::Mechanize::Chrome
by Corion (Patriarch) on Dec 23, 2018 at 12:55 UTC

    I have to apologize - you reported this problem as a bug in WWW::Mechanize::Chrome and I rejected that bug because I could not reproduce it. But it is an actual bug. With your posted code above, I can easily reproduce the issue and the problem is that the code does not cope with a Page.navigatedWithinDocument element at all.

    I've added the following code to WWW::Mechanize::Chrome, which should fix that issue, or at least not crash anymore:

    } elsif ( my $res = $events{ 'Network.responseReceived' }) { #warn "Network.responseReceived"; $response = $self->httpResponseFromChromeResponse( $res ) +; $response->request( $request ); + } elsif ( my $res = $events{ 'Page.navigatedWithinDocument' }) { + # A fake response, just in case anybody checks + $response = HTTP::Response->new( + 200, # is 0 for files?! + "OK", + HTTP::Headers->new(), + ); + $response->request( $request );

    A new version of WWW::Mechanize::Chrome is just testing and then on its way onto CPAN.

      Works perfectly now. Thanks so much for the quick fix.

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