Some web projects require us to run web apps of others to perform automated actions on systems without APIs or to scrape, for example, without the use of a browser, in a script or cron job, for instance.  This is called headless browsing.  The trouble is, some sites rely heavily on JavaScript and a full blown browser environment is required to get anywhere with such a setup.  This problem is so hard that a lot of web sites make use of JavaScript to prevent automated systems from using their sites.  A project of a scraping kind for such a site would require a lot of hard work and graphics libraries on the server to get WebKit or Chromium to work with our code.  Fortunately, the web developer community has been hard at work on solutions to this novel problem.

JavaScript Engine

First, you need a javascript engine to be able to execute javascript. There are a number of possibilities,

There is V8 php extension in existence which should allow easy JavaScript execution within a PHP script.

DOM

Once we can execute JavaScript, we need DOM bindings to get web page’s DOM specific code to run properly. For this, my recommendation is to use purely JavaScript-based implementation to simplify the stack.

The Quick & Easy Way

If you are looking for an easy way without too much coding, I recommend PhantomJS, which is a WebKit-based solution.