Thursday, May 24, 2007

Screenshots of Web Pages

It is not a problem to make a screenshots of web pages if you have running firefox on your desktop. But if you can’t start X11 (X.org), it is not so trivial. So the post is about how to create screenshots of web pages via firefox without X11 (X.org) server.

Unfortunately Firefox can’t work without a display it can connect to. Fortunately there are standard tools which allow to create the necessary environment without starting of X11 (X.org) server. Xvfb tool must be installed.

First of all extract the Firefox to some folder and start it in order to allow it to create profile in your home directory. Right now you need Xvfb.

$> Xvfb -ac -screen :0 1024x768x16 2>&1 > /dev/null &
$> firefox

Now you can terminate Firefox with Ctrl-C and continue the setup. We need a minimal Firefox application panels to make a good screenshots. Thus the Firefox have to be started in a full screen mode. The extension Autohide is very useful here. Just install it:

$> firefox -install-global-extension autohide.xpi

This command does not need X11 environment and will be successful. After the installation firefox will understand new command line option -fullscreen.

Also Firefox noises with various popups: yellow bar with prompt for plugin install, confirmation for previous session restoring, etc. The following setup strings disable most of them:

user_pref("browser.sessionstore.enabled", false);
user_pref("browser.sessionstore.resume_from_crash", false);
user_pref("browser.startup.page", 0);
user_pref("plugin.default_plugin_disabled", false);
user_pref("privacy.popups.disable_from_plugins", 3);
user_pref("alerts.totalOpenTime", 1);
user_pref("security.enable_ssl2", false);
user_pref("security.enable_ssl3", false);

The strings have to be placed in the file ~/.mozilla/firefox/XXXXX.nameofprofile/prefs.js Please see the site http://kb.mozillazine.org/Knowledge_Base for explanation of all this options. The topic is not about it.

If the Firefox and Xvfb are installed you can try to make a screenshot.

# first of all we have to start Xvfb (if not started yet)
$> Xvfb -ac -screen :0 1024x768x16 2>&1 > /dev/null &

$> firefox --display=:0 http://www.google.com/ \
-silent -nosplash -fullscreen 2>&1 > /dev/null

# dump X screen to file
$> xwd -root -out -display :0 screen.xwd

# convert dump file to some usual format
# and crop possible scrollers of Firefox
$> convert screen.xwd -crop 1005x768 screen.png

# care about closing of Xvfb and firefox
$> kill `pidof firefox`
$> kill `pidof Xvfb`

The same, for explanation of what is Xvfb, xwd, convert, pidof and kill tools please see the corresponding man pages, since it is not a subject of this topic.

1 comments:

Vitor said...

You can skip the xwd and convert to png, by using the import command:

DISPLAY=:1 import -window root captured.png

Then crop the scroll bar and proceed.