Corion / WWW-Mechanize-Chrome

automate the Chrome browser
https://metacpan.org/release/WWW-Mechanize-Chrome
Artistic License 2.0
30 stars 12 forks source link

HTTP::Response from ->get does not return content #41

Closed KES777 closed 5 years ago

KES777 commented 5 years ago
    36: sub url2pdf {
   x37:     my $chrome =  shift->chrome;
   x38:     my $res =  $chrome->get( shift );
   x39:     DB::x;
  >>40:     $res->is_success  &&  $res->content   or return;
   x41:     return $chrome->content_as_pdf( format => 'A4' );
    42: }
    43:

DBG>$res
HTTP::Response {
  _content => ,
  _headers => HTTP::Headers {
    content-length => 4561,
    content-type => text/html;charset=UTF-8,
    date => Mon, 27 May 2019 11:37:49 GMT,
    server => Mojolicious (Perl),
  },
  _msg => OK,
  _rc => 200,
  _request => undef,
}

DBG>$res->content

As you can see HTTP::Response object has 4561 bytes of content, but ->content returns nothing. Also _content is empty

Corion commented 5 years ago

Ouch! The response body is filled in asynchronously, so maybe you can circumvent the issue by waiting some time (1s should be well enough) as a workaround.

The real fix is to return a proxy object that blocks when the ->content (or ->decoded_content or whatever) methods are called to wait for the fetched content.

KES777 commented 5 years ago

please put a note into documentation