I'm new to phantomJs. I've installed phantomjs in my system(Ubuntu) and executed a sample code "test.js" in terminal like,
test.js:
console.log("WELCOME TO PHANTOMJS");
phantom.exit();
In terminal
phantomjs test.js
its executed fine shows expected output.
NOw my question is, Is there any possibilites to execute above js file in a browser by importing that js file in a html file like,
<script src="test.js".....></script>
If is it possible means how to do?? Please help me.
I'm new to phantomJs. I've installed phantomjs in my system(Ubuntu) and executed a sample code "test.js" in terminal like,
test.js:
console.log("WELCOME TO PHANTOMJS");
phantom.exit();
In terminal
phantomjs test.js
its executed fine shows expected output.
NOw my question is, Is there any possibilites to execute above js file in a browser by importing that js file in a html file like,
<script src="test.js".....></script>
If is it possible means how to do?? Please help me.
Share Improve this question asked Oct 30, 2013 at 6:07 user2810903user2810903 711 silver badge6 bronze badges1 Answer
Reset to default 6Short Version
You can't
Detailed Version
In its current state, PhantomJS is a standalone process and needs to have the full control (in a synchronous matter) over everything: event loop, network stack, and JavaScript execution, ... yes you write scripts in Javascript but it's simply because it exposes a JavaScript API (also for coffee script).
"How to execute a nodejs module in browser?" It's pretty the same problem and you simply can't because of phantomjs/nodejs dependencies : what is webpage
module in your favorite the browser ? But it's still possibe to share pure JS library.
So, you can't directly reference a phantomjs script in your browser, but you can municate with a PhantomJS instance using HTTP GET/POST with Web Server module. HEre is a topic onInter Process Communication found on the Wiki.