server side browser - javascript

I was wondering if it is possible to run a browser (specifically a browser engine) on the server side. I do not just mean to render a page but to keep a browser open for some time, run some JS, do some clicks or press some keys and meanwhile grab the graphical output.
Does anyone know how to accomplish this? So far my only idea was to run the browser in a VNC, RDP etc. session but this seems like an overkill to me.

PhantomJS does what you are describing. It is basically a headless browser - http://phantomjs.org/
you can run it server side via any server side language. See some integration modules below for NodeJS and PHP
NodeJS
https://npmjs.org/package/node-phantom
https://github.com/sgentle/phantomjs-node
PHP
https://github.com/diggin/php-PhantomjsRunner

Yes, it it very possible to run a web browser on a server. Ubuntu Server, for example can run firefox by simply installing firefox and xserver.
$ sudo apt-get install firefox
$ sudo apt-get install xserver-xorg
Then to get firefox running type:
$ X
This will leave you with a blank screen because there are no applications running on the display yet. You need to shift back to a new terminal with
Ctrl-Alt-F2. Ctrl-Alt-F1 holds the X process now.
Login to the new terminal and set the environment’s display variable to :0 and launch firefox.
$ export DISPLAY=:0
$ firefox &
Firefox should now be running, but you'll notice it's got some quirks to it. If you decide that you want to go forward with this you should install a window manager. I'd go with a lightweight tiling window manager and run firefox and whatever other applications need graphical output within that window manager.

Related

Changes to minio browser do not appear when running minio server

My goal is to modify the Minio browser for front end appearance in house. I'd like to add features too but can't seem to get either to work and feel like I'm missing something about how go accesses npm or the browser.
I have made changes to the Minio web browser (javascript) and can see them when running with npm (in ./browser 'npm run release;npm run dev'), but when I try to run minio server built with the same git clone (changes is browser subdir) and browse to localhost:9000 I don't see any of the changes.
It would also be nice to run the browser with npm and connect to the running server "./minio server ~/data", but they don't seem to talk and I'm unclear on how they're connected.
This seems to be a simple case of all the things I tried and in the right order.
Correct order:
cd browser; npm run release
cd ..; make
./minio server ~/minio-data
It seems I'd tried all of these separately but not in the obvious order. I'm assuming npm makes the ui-assets.go which gets included by the make

Node.js emits runtime error when listen to port 9999

I'm completely new to nodeJs, and just to learn step by step. I managed to download, run nodeJs via the CMD and tested by creating file, all works fine. The problem now is when I want to tell nodeJs to display the output on the browser instead. I simply followed the tutorial but I'm getting runtime error. I suspect the port is somewhat wrong. Which port no I should use here, is it my localhost port which is 80, I tried it to no avail.
Here's the error message:
Referred here:Using node.js as a simple web server
All I want is to be able to see the output in the browser via nodeJs. I think the port 9999 is meant for tcp connection as I'm learning for real-time app.
You're not using NodeJS to run your code. To run your code using NodeJS, run them with node:
node c:\projects\test\helloweb.js
The reason what you tried didn't work is that typing c:\projects\test\helloweb.js in cmd.exe and pressing Enter will not run the code in a browser, or in NodeJS. It will try to run it using whatever application you have associated with .js files. The Windows default, which is what your computer is using, is to use Windows Script Host (as you can see in your error message). WSH provides a runtime environment that's quite different from NodeJS and quite different from a browser.
If you read the dialogue carefully you'll see its title is "Windows Script Host", not Node. In fact Node is a command-line tool that doesn't launch dialogues or other widgets. Your screenshot clearly shows you were doing it just fine and then eventually forgot to type node in your command:
FYI, Windows Script Host is a tool that's similar to Node (a server-side ECMAScript engine) but belongs to another vendor (Microsoft), uses a different ECMAScript implementation (JScript) and possibly hasn't been updated in 10 years. That means that features and available libraries are completely unrelated to those in Node.

Node-webkit app talk to terminal

Is it possible for me to write html/css/javascript to have a button that'll open up the terminal program on my computer and run some scripts?
The scenario I want is:
On my ubuntu laptop, run my node-webkit app, click a button on the screen, a terminal opens, and start executing some scripts.
Thanks
from web page you cant do this but you can use node.js , if you want to make a GUI app with JavaScript you can use node-webkit with it you can build cross platform software that can work with Linux and execute commands in the terminal
You can do this from a webpage, but make sure your hosts.allow (or equivalent) is set to localhost only. Just run any web server with cgi capability and drop in your cgi script that runs your scripts into the cgi-bin directory. Then just add an empty form submit button or link to localhost:8080/cgi-bin/your_script
Slitaz uses this for their entire configuration system using busybox httpd and shell scripts, but uses shell generated interactive forms instead of a terminal. See: http://hg.slitaz.org/tazpanel/file/
Another way to do it without a web server (at least with firefox/seamonkey - not tried with chrom) is to associate a file extension so that files with that extension are opened with that script. Then just make a link to an empty file with that extension.
Use child_process module:
<script>
var cp = require('child_process');
function run() {
cp.exec('gnome-terminal -x bash -c "./your_script.sh; read -n1"');
}
</script>
<button onclick="run()">your_script.sh</button>
You can also remove read -n1 and simply run
cp.exec('gnome-terminal -x ./your_script.sh');
in case you don't want to wait for any key press.

How to debug node.js application with Visual Studio 2013 and Node Tools NTVS

I have moved an existing node.js + express project to VS because I prefer the IDE over JetBrains for now (used VS for years, only peeked into Webstorm).
I used NTVS new project->from existing sources and all files were imported successfully.
Afterwards, I opened the project settings of my project and set the node.exe arguments to bin\www, startup file for express.
When I press F5 (debug) I get the console.log messages I have put into the www and app.js files in the opening command prompt, and it looks like the server is running (cannot confirm, I want to debug if everything is working), but the VS debugger directly exits again, it also does not open any page in the browser I selected for debugging.
My node app actually is a REST webservice, so I want to test different URLs with different parameters.
Also, I cannot access the app on the port I specified, though when I directly start it from node.exe I can, even though the command prompt is still open.
(I have NTVS and WebEssentials installed - some operations take a long long time, but I attribute this to NTVS being still an early version.)
Question: how does the Visual Studio debugger stay connected to the node.js application so I can use breakpoints and use any browser then to connect and test different URLs? (Even a breakpoint put on the console.log that gets printed during startup is not being triggered.)
For everyone who asks receives, and the one who searches finds....
(and yes, I did spend a long time searching and trying before posting here..)
Kind of nice to debug node.js server with VS..
hope this helps someone
Edit: The arguments to node.exe can be hard to read in the image. It must be
--debug=<portno>
that is with two dashes (and not just one) to specify the debug port.
Not so much knowledge on expressjs but with a recent release of NTVS 1.0 Alpha, I did find it supports remote debugging which can be also used to debug nodejs app running locally - anyway haven't tried if it works with nodejs app + expressjs but it should.
I followed the step in this video https://youtu.be/-ir9ZB8lUg4 which is
Run your nodejs with node.exe RemoteDebug.js <your_javascript_file>.
RemoteDebug.js has come when you install NTVS.
In Visual Studio, select Debug > Attach to Process
Select Node.js remote debugging for Transport
Enter localhost:5859 for Qualifier
Click Attach
This will put Visual Studio in debugging mode which you can set a breakpoint, do step-in/step-out, very same experience when you use VS to debug .NET app.
Its pretty straight forward with NTVS, you can download required version for your windows from github here
Once you install NTVS, NodeJS project templates will be added
Now, Goto File->New project -> Basic NodeJS Express 3 application (it will be available in javascript project templates)
Now just goto debug and select Start Debugging, add breakpoints where ever required and you can start debugging

How to test rails javascript and ajax without a browser

When i use RSpec with Capybara to test my rails javascript page, I get the following error:
Selenium::WebDriver::Error::WebDriverError: Could not find Firefox binary (os=linux).
Actually my rails scripts are all written on the linux server, where there is on brower installed, and desktop software is not supported on the server (since X11 is not installed).
How can I test javascript in this situation. Or is there a brower that works without X11 installed like wget? Thanks.
What you want is the capybara-webkit gem, which will allow you to run your browser tests in "headless" mode, i.e. without an actual browser being open. You'll need to install QT (a cross-platform development toolkit) to get it to work, because it uses the QT webkit. See the documentation for details on installing on different OSs.
I use this setup for my js-dependent tests and it works like a charm.

Categories

Resources