Subject: | viewport_size method sets clipRect property instead of viewportSize property |
Date: | Fri, 7 Nov 2014 14:06:55 -0700 |
To: | bug-WWW-Mechanize-PhantomJS [...] rt.cpan.org |
From: | Maxwell Carey <mcarey [...] ucar.edu> |
The viewport_size method sets the PhantomJS clipRect property, but it
should set the viewportSize property. The attached programs viewport.js and
viewport.pl and the generated images viewport_js.png and viewport_perl.png
demonstrate the problem. Calling
viewport_size({ width => 1388, height => 792});
should make the loaded page fill a 1388x792 box. Instead the page fills its
default viewport (I believe 400x300) and then a 1388x792 box is clipped, so
the page only fills up a portion of the top-left corner of the generated
box.
viewport_size doesn't work properly as a getter either, as demonstrated by
the following:
use strict;
use warnings;
use Data::Dumper;
use WWW::Mechanize::PhantomJS;
my $ghostdriver_path =
'/usr/local/share/perl5/WWW/Mechanize/PhantomJS/ghostdriver/main.js';
my $mech = WWW::Mechanize::PhantomJS->new(launch_arg => [ $ghostdriver_path
]);
print 'Before: ' . Dumper $mech->viewport_size;
$mech->viewport_size({ width => 1388, height => 792 });
print 'After: ' . Dumper $mech->viewport_size;
Outputs:
Before: $VAR1 = {};
After: $VAR1 = {};
I've attached a patch that fixes both of these issues. The content_as_png
method was actually calling viewport_size if the user passed in a hashref
of coordinates, even though the documentation says, "If the coordinates are
given, that rectangle will be cut out." I also fixed content_as_png to use
the clipRect property instead of calling viewport_size.
I only did some limited testing, and I'm not sure if this patch breaks
anything in the existing test suite, so it would be a good idea to check it
thoroughly.
Message body not shown because it is not plain text.
Message body is not shown because sender requested not to inline it.
Message body is not shown because sender requested not to inline it.
Message body is not shown because sender requested not to inline it.
Message body is not shown because sender requested not to inline it.