Automated screenshots in Firefox with WWW::Mechanize::Firefox

I was reading presentation slides from YAPC::EU 2010 and found this one: Web Automation with WWW::Mechanize::Firefox. It explains a module that connects to a running Firefox instance and will use it to follows links, create screenshots and more.

I rewrote the example a little bit make it work. I ended up with the this. These are two methods that work. The original method didn't work for me

# The original line in the example
my $png = $mech->content_as_png();

# Method 1
my $png = $mech->element_as_png($mech->selector('html')); 

# Method 2
my $png = $mech->content_as_png(undef, 
                {left=>0,top=>0,width=>200, height=>200});

Now I can automatically create screenshots from webpages. I will still need some way to control the width of the page and maybe a way to crop parts. I could use the element_as_png method for cropping, which allows me to get a screenshot of part of a page, maybe that's enough.


My name is Peter Stuifzand. You're reading my personal website.