3

I need to load a page once per hour and execute the javascript on that page. I currently load the page manually with Firefox, but I would like to automate this by running a cron job on the server, which is Ubuntu Server 8.04 LTS.

Some web searching suggests that the best thing would be to run firefox -remote openurl(...) and let gecko run the javascript, but this requires X11 which I don't know how to simulate on a server install.

So essentially I want an hourly job to run firefox in a simulated environment and discard the output. (I'm not wed to firefox... I'd happily take a wget-like command that executes javascript.)

Fixee
  • 1,911
  • 3
  • 18
  • 25

3 Answers3

3

Just to add this to the mix, we ended up using HTMLUnit instead of the above.

Fixee
  • 1,911
  • 3
  • 18
  • 25
2

You could try http://www.phantomjs.org/ a headless WebKit browser.

  • Thanks for the pointer, Joby, but it looks like PhantomJS requires Xvfb anyway (ie, it's not really headless) so I'm probably just going to use Firefox (which I don't have to build myself). – Fixee Apr 05 '11 at 00:31
2

You can run a graphical browser (e.g. Firefox) that's displaying in a virtual X server (Xvfb). See How can I run Firefox on Linux headlessly (i.e. without requiring libgtk-x11-2.0.so.0)?, and perhaps also How do I start Xvfb on startup on Debian?.

Elinks is a text mode browser with optional Javascript support. The version in Ubuntu 8.04 is compiled without the JS support, so you'd have to compile your own and link it with the Mozilla SpiderMonkey JavaScript library. These instructions in the manual may help.