Simulating a web browser on your server
Programming, Web Development July 10th, 2007 - 1,714 viewsJohn Resig, a programmer working for the Mozilla Corporation and creator of the wonderful jQuery JavaScript library spent last weekend putting together a server-side browser/DOM environment that he’s released on his blog. The application, written entirely in JavaScript, runs on top of Mozilla’s open source JavaScript implementation called Rhino.
I can think of a number of situations where this sort of environment could be extremely useful. As John mentions, web programmers could use a server-side Javascript implementation to automate testing of complex client-side applications. The possibilities for simple screen scrapers, as well as sophisticated web spiders are also intriguing. Search companies could conceivably use this environment to built a spider that understands JavaScript and interacts with modern web applications the same way humans do.
Setting up the environment is pretty simple. First, download the latest release of Rhino from Mozilla FTP. Next, grab a copy of John’s env.js script and place it in the same directory as the Rhino js.jar. Finally, launch Rhino then load up the environment, and a website:
load('env.js');
window.location = 'some.html';
window.onload = function(){
// Your code here
};
For more details, along with some example use cases, head on over to John’s blog.
Recent Comments