4

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?

2
  • 2
    Do you mean a headless browser, like PhantomJS? Commented Feb 28, 2013 at 9:24
  • yes a couple of google searches and could not find this...looks just the think....will give it a try and update ticket...thanks alot Commented Feb 28, 2013 at 9:27

2 Answers 2

5

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:

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

  • HTMLUnit (I use that one for unit testing)
  • PhantomJS
  • Zombie.js
Sign up to request clarification or add additional context in comments.

5 Comments

standalone seems to be JS from command line...i need it to be able to do everything a browser can do but without a browser...thanks anyway
doing everything that a browser can do sounds a lot like you will end up needing a browser, so you mean like a browser but without the window/UI ?
yes, so a script can open/execute a website many times over and produce same results as if a user was...it can be very useful for a lot of things commercial and personal
ah I see, I updated my answer accordingly, I use something similar like this myself for unit tests
Phantom.js is currently dead (github.com/ariya/phantomjs/issues/15344) for new development.
0

Running JavaScript on the command line by using either Rhino for Java or Windows Script Host.

http://www.mozilla.org/rhino/

http://msdn.microsoft.com/en-us/library/9bbdkx3k%28VS.85%29.aspx

2 Comments

hmm rather not using Java and dont trust anything microsoft come out with lol...sorry but think im going to go with PhantomJS @Teemu has mentioned
Ok this was just another way. Good you got answer :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.