I needed to save web pages screenshots. The closest option to my initial environment was Fedora Linux 16 on Amazon EC2 is python-webkit2png.

To make it work on the headless server and render flashes I had to:

Get the base Fedora AMI running, I’ve selected the first one I’ve found (ami-7bf4c90f) and ran it as micro

yum installĀ  wget unzip PyQt4 qtwebkit xorg-x11-server-Xvfb-1.11.4-3.fc16 dejavu-* liberation-*
rpm -ivh http://linuxdownload.adobe.com/adobe-release/adobe-release-i386-1.0-1.noarch.rpm
yum install flash-plugin
wget https://github.com/AdamN/python-webkit2png/zipball/master
unzip -x master
cd AdamN-python-webkit2png*
python setup.py install

And you should be ready to go

Test run it like this:

webkit2pngĀ  -W -o goo.png -w 20 -F javascript -F plugins -g 1280 1024 -x 1280 1024 http://www.wechoosethemoon.org/

And you should see that it doesn’t render flash. Thing is you have no browser on the server so plugin directories where webkit expects to find them are not there. Create one and link the flash plugin:

mkdir -p /usr/lib/mozilla/plugins && ln -s /usr/lib/flash-plugin/libflashplayer.so /usr/lib/mozilla/plugins/

redo the test above and you will see the flash rendering. but somehow –wait option doesn’t seem to work so the rendering doesn’t finish so you will only get progress bars when there is lots of data the initial swf pre-loads. It seems like a problem in webkit2png.py around line 219 (/usr/lib/python2.7/site-packages/webkit2png-0.8.2-py2.7.egg/webkit2png/webkit2png.py):

waitToTime = time.time() + self.wait
while time.time() < waitToTime and QApplication.hasPendingEvents():
QApplication.processEvents()

If there are no QApplication pending events the while will break out and will not wait. I am not sure what the problem really is but changing it to this:

waitToTime = time.time() + self.wait
while time.time() < waitToTime:
if QApplication.hasPendingEvents():
QApplication.processEvents()
makes the waiting work. I will open an issue on the github to let people know.

 

Update: Another issue with flash.
Seems like the window is resized too late and flash doesn’t update its geometry thus creating 800×600 screenshots. This fix seems to make things work better:
in the WebkitRenderer.render(), resize the window just after the helper is created:

       helper = _WebkitRendererHelper(self)
       helper._window.resize( self.width, self.height )

Post Navigation