Execute browser page/javascript from a script/command-line

headless-browser, html, javascript, v8

Solution

You can use any js engine to run js scripts as long as they do not rely on the DOM.

You could start by looking at:

- Running V8 Javascript Engine Standalone

Edit: as I understand you want a headless browser, here are some:

- HTMLUnit (I use that one for unit testing)

- PhantomJS

- Zombie.js

Problem

Hope this isnt a stupid question. I have recently had an idea about something which I am very curious about. I am a fan of Node.js (not really relevent here I think) and the V8 engine but I was wondering if its possible to run a browser (get it to execute JS) but INTERNALLY. What I mean by that is to create a program (possibly using the V8 engine) which can open a page (as if in the browser) and execute its javascript. For instance say I have the below file hosted on www.mysite.co.uk/home.php ``` <!DOCTYPE html> <html> <head> <script> function myFunction() { //javascript AJAX call to www.mysite.co.uk/ping.php } myFunction(); </script> </head> <body> </body> </html> ``` And ping.php looks something like: ``` <?php //connect mysql, database ping and table ping //it is a single column table with integer value starting on 0 //increment by 1 and update the table ``` Say I wanted to get the Javascript to execute by using some sort of script on my command line/linux box (essentially WITHOUT using a browser). So something like: ``` ./mybrowser http://www.mysite.co.uk/home.php ``` or even: ``` ./mybrowser home.php ``` I feel like it should be possible as the V8 (or different JS engine) should technically be able to execute Javascript but I havnt the foggiest how it could do so out of a browser context (or even if its possible). Any ideas?

Original source

Related problems