简体   繁体   中英

Is there any way to open a browser from different machine using node js?

I am just curious to know, is there any possibility to open/trigger a browser from different machine in same LAN using NodeJS.

I have gone through node's default 'http.createServer()' and browserSync. Using them I can create a server and open the page in other machine's. But dont know how to trigger the browser/tab automatically in them.

Thanks!

This is a massively over simplified solution to your problem, and as you're aware there are significant security considerations around this functionality.

However, using open this can be done quite easily on a local network (providing the correct firewall rules are in place).

Computer B (the machine the browser should open on):

var http = require('http');
var open = require("open");

function handleRequest(request, response){
    open("http://www.google.com", "firefox");
}

var server = http.createServer(handleRequest);

server.listen(8080, function(){
    console.log("Server listening on: http://localhost:8080");
});

Computer A (the machine to trigger the browser opening from):

var http = require('http');

var options = {
  host: '<Computer A IP address>',
  port: 8080,
  path: '/'
};

http.request(options).end();

While running the code on computer B, if you run the computer A code then it should open Firefox at http://www.google.com on computer A.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM