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.
Short 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 communicate with a PhantomJS instance using HTTP GET/POST with Web Server module. HEre is a topic onInter Process Communication found on the Wiki.
Related
I have a personal SPA running Vue, which uses a library (lets call it foo). foo download a javascript file called bar.js and then execute it. Everything works as expected, but in bar.js there is an https call (https://fixed-domain/fixed-param) which slows down my SPA significantly. I've tested with uBlock Origin extension that simply blocking the call would solve my problem.
So, is there a way to block that https call from my Vue app? I've try reading the source code of uBlock but it is too complicated for me to re-implement it.
Since phantomjs is abandoned, I would like to know if there is any alternative method. e.g. chrome-webdriver wouldn't be a good solution as it wouldn't be able to run on a remote host such as heroku.
So, is it somehow possible to scrape an external website that require javascript being triggered first? Note that it should be possible to run it from a nodejs application.
I was getting ready to put together something for you, then I thought better and google'd it. Check out this build script; it seems to answer your question exactly.
https://github.com/stomita/heroku-buildpack-phantomjs
Set up a git branch and pull it locally if you have to, but this should work. Basically, you need to download the binary and then remote in and run "heroku run 'phantomjs'" or "heroku run 'bin/phantomjs'"
I have a html file that when run in a browser such as Chrome and that contain javascript instructions, it sends the "emit" message to my websockets server and displays the value on that page.
Is there a way to call this same html file from a bash script as I'm wanting to insert data into a MySQL database which will ultimately call that html file to send an update to the websocket.
Hopefully that makes sense but hopefully there is a way to do it too :)
If you are only focused on rendering the HTML page (and not interacting with it via buttons or something) you may find this link helpful: Running HTML from Command Line
If you try to execute javascript instruction in your server without using a browser, I recommand you to use Node.JS with a real js script without html.
Otherwise you can try to run an html file with js instruction inside using something like phantomjs but I think is less performant than using Node correctly.
EDIT
It is Javascript yes, but I need to "Import" the socket.io.js file into the same script I have created and my browser I'm having to use doesn't support the new Javascript import methods. So I'm writing as HTML which calls the Javascript, otherwise I would use nodejs
I think you can import the socket.io lib in node application using npm.
https://www.npmjs.com/package/socket.io
The documentation says that you can use a client inside a node script too :
Socket.IO enables real-time bidirectional event-based communication. It consists in:
a Node.js server (this repository)
a Javascript client library for the browser (or a Node.js client)
Given that I have a local Perl script that prints "Hello" in a windows command prompt.
I want to make a Web Interface that when I click a button on an HTML page using Javascript or something, I'd be able to execute this local Perl Script. I have tried hosting the page on Localhost in an Xampp Apache server however this uses the Perl installed on Xampp.
Is there anyway to interact with local Perl from a Web User Interface? i.e. Running a perl script in the local shell from a Web UI.
I usually run a perl script that works as a primitive web server. Upon startup it prints a URL which can be used to access it.
This can be done with the following modules:
use HTTP::Daemon;
use HTTP::Status;
use HTTP::Response;
in about 60 lines of code.
Can't post my code, but here is a more elaborate sample (it uses fork, which is an improvement over what I have): http://www.perlmonks.org/?node_id=415908
Look into Node JS... it can call perl from the webpage, is very very simple to set up and get a localhost site going, and is free.
in a simple html file opened locally via firefox I need some javascript code to execute a command (maybe "ls") and get it's result in a string I can use in js/jquery to alter the page contents.
I already know this is a generally bad idea, but I have to make this little local html file capable of running several scripts without a server and without cgi.
In the past I've used to install a plugin in TiddlyWiki (www.tiddlywiki.com) to execute external commands (firefox requested authorization for every operation), so javascript can do it, but how to get command result in js after execution?
I don't believe there's any way to do this without a cooperating browser plug-in. The browser plug-in would be told what command to execute via javascript, it would go execute that command and then call you back with a callback when the results were available. This could be very dangerous as giving the browser access to your local system in almost anyway opens you up to lots of types of attacks (which is why browsers don't offer this capability).