Search code examples
perlfirefoxscreenshotmechanize

Perl WWW::Mechanize::Firefox screenshots don't include backgrounds


I don't know if this is possible or not, since I only just started using and learning Perl today, but I installed the WWW::Mechanize::Firefox module and made sure to install the mozrepl plugin in Firefox itself to see if I could take screen shots of websites.

The script works and saves png files of website screenshots as expected. However if the website uses background colours and background images they are not included in the screenshot.

Is there a way to include these things or do I have to accept that this is just how it works?

For reference this is my simple test script:

use WWW::Mechanize::Firefox;
use Path::Class qw/file/;

if(@ARGV == 2) {
    my $mech = WWW::Mechanize::Firefox->new(
        launch => 'C:\Program Files (x86)\Mozilla Firefox\firefox.exe',
        tab => 'current',
        autoclose => 'close|q',
        mozrepl => 'mozrepl|m:s'
    );

    $mech->get($ARGV[0]);

    my $fh = file($ARGV[1])->open( '> :raw' );
    print $fh $mech->content_as_png();
};

Solution

  • This sounds like what happens when you print a webpage

    By default, background colors/images aren't used.

    Firefox has a setting to enable printing those