Environment setup
PhantomJS is a beautufil product to launch a headless web browser or your linux server. This can be used to automate a large amounts of tasks which can't be processed with raw curl.
So we have CentOS release 5.7 (Final), 32bit, and need to get completely loaded websites with Flash support. PhantomJS isn't supported Flash plugin since 1.5.0, so we need to use 1.4.1 version. All components can be installed via these guides: rhythmicalmedia.com/?p=146 and code.google.com/p/phantomjs/wiki/XvfbSetup. All should be OK (maybe except the GIT insallation - but phantomjs-1.4.1 is in source code, so no actual usage of GIT).
To start Xvfb you need to add these strings to /etc/init.d/Xvfb
# chkconfig: 345 99 50
# description: Simple graphical server
To make chkconfig work with it. You may need xfvb-run script, one can be obtained from here www.minecraftwiki.net/wiki/Programs_and_Editors/Tectonicus/VPS.
Flash plugin installation routine
rpm -ivh http://linuxdownload.adobe.com/adobe-release/adobe-release-i386-1.0-1.noarch.rpm
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-adobe-linux
yum check-update
yum -y install flash-plugin nspluginwrapper
Command line must contain option --load-plugins=yes - so the correct ones will be
export LIBXCB_ALLOW_SLOPPY_LOCK=1;DISPLAY=:0 ./phantomjs --load-plugins=yes ../examples/rasterize.js URL SCREENSHOT_FILE
or
export LIBXCB_ALLOW_SLOPPY_LOCK=1;xvfb-run --server-args="-screen 0, 1024x768x24" ./phantomjs --load-plugins=yes ../examples/rasterize.js URL SCREENSHOT_FILE
Also to emulate Flash support in phantomjs browser you need to add before page.open the following (at least plugins and mimeTypes - to pass all Flash detection tests correctly)
page.onInitialized = function () {
page.evaluate(function () {
window.navigator = {
plugins: {length: 2, 'Shockwave Flash': {name: 'Shockwave Flash', description: 'Shockwave Flash 11.6 r602'}},
mimeTypes: {length: 2, "application/x-shockwave-flash":
{description: "Shockwave Flash", suffixes: "swf", type: "application/x-shockwave-flash", enabledPlugin: {description: "Shockwave Flash 11.6 r602"}}
},
appCodeName: "Mozilla",
appName: "Netscape",
appVersion: "5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22",
cookieEnabled: true,
language: "en",
onLine: true,
platform: "CentOS 5.7",
product: "Gecko",
productSub: "20030107",
userAgent: "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22",
};
});
};
If you have any troubles with failed flahs plugin initialization (on screenshots) you may need to downgrade to version 10 by the following command
yum erase flash-plugin
rpm -ivh http://dl.atrpms.net/el5-i386/atrpms/bleeding/flash-plugin-10.2-1.i386.rpm
All this makes headless PhantomJS browser work with modern Flash websites.