Ted’s Mozilla Blog
If this were a diary it would have a unicorn on the cover, because unicorns are awesome.
moz-headless-screenshot
July 29th, 2010
On a personal project of mine, I have a need to generate thumbnails of web pages. Until recently my solution was to use Firefox running in Xvfb, a virtual X server. This is not an ideal solution, as it requires you to have lots of X client libraries installed on your server. Additionally, Firefox is not intended for this purpose, so there are lots of ways for things to go wrong.
Because of this, I’d been following Chris Lord‘s work on theoffscreen branch of Mozilla for some time, but never tried it out until recently. The offscreen branch provides a widget backend for Mozilla that can render web content to an offscreen buffer. Chris wrote it in support of Clutter, which is a pretty neat use case. Conveniently, he also provided a sample embedding client application called moz-headless-screenshot. This is a simple command line tool that takes a URL, image size, and output filename and generates a PNG screenshot of the webpage. This being exactly what I wanted, and having my poorly-written Firefox+Xvfb solution fall apart due to a server migration, I decided to give his solution a shot.
I hit a few speed bumps on the way, since there wasn’t much documentation to be found on actually building and using moz-headless-screenshot. I’ve attempted to fix this my providingdetailed steps and a Makefile in my own moz-headless-screenshot repository. I’ve also modified the code slightly such that it’s easier to run (at least in my use case). I have heard from others over the years that have this same need, so hopefully someone else finds it useful!
July 29th, 2010 at 12:37 pm
If I’m understanding, this should work similarly for a Windows user:
Nirsoft: [url=http://www.nirsoft.net/utils/web_site_screenshot.html]SiteShoter – Take a screenshot of a Web site [/url]
“SiteShoter is a small utility that allows you to save a screenshot of any Web page into a file. It automatically creates hidden window of Internet Explorer, loads the desired Web page, and than save the entire content of the Web page into an image file (.png, .jpg, .tiff, .bmp or .gif).
You can also use SiteShoter to convert .html file on your local drive into image file.
You can use SiteShoter in user interface mode, or alternatively, you can run SiteShoter in command-line mode without displaying any user interface.”
July 29th, 2010 at 2:59 pm
This is very useful to me, thanks for blogging about this!
For work I put together a website-to-PDF script using Firefox and Xvnc on Linux (easier to debug problems than Xvfb IMHO) but it’s a PITA all around, it’d be nice to have fewer moving parts for sure.
July 29th, 2010 at 11:55 pm
I’ve been using wkhtmltopdf for, well, exactly what the name says. That uses Webkit, but it would be wonderful to have something Gecko based.
July 30th, 2010 at 12:13 am
Hmm, what’s wrong with gnome-web-photo which is also using Gecko (in certain builds)?
July 30th, 2010 at 11:32 am
gnome-web-photo has additional dependencies on Gnome libs which I don’t want to install. Also, it still needs an X server, AFAICT. (Although if it was built against the offscreen branch, it might not.)
August 3rd, 2010 at 6:25 am
Awesome, glad some people have found use for it Would be great if someone picked up the work and managed to get it into master…
http://www.holovaty.com/writing/headless-html-rendering-engine/
http://mink.behat.org/#understanding-the-mink
Mink
CHAPTERS
Web acceptance testing
One of the most important parts in the web is a browser. Browser is the window, through which web users interact with web applications and other users. Users are always talks with web applications through browsers.
So, in order to test, that our web application behaves correctly, we need a way to simulate this interaction between browser and web application in our tests. We need a Mink.
Mink is an open source acceptance test framework for web applications, written in PHP 5.3.
Installation
Mink is a php 5.3 library that you’ll use inside your test suites or project. Before you begin, ensure that you have at least PHP 5.3.1 installed.