开发者

Is it possible to create a browser extension to allow for incoming requests?

开发者 https://www.devze.com 2023-04-13 04:47 出处:网络
I am looking to figure out a way to make incoming request to a browser.Installing an extension in the browser is OK.The goal of this is to allow anot开发者_JS百科her machine to connect to the extensio

I am looking to figure out a way to make incoming request to a browser. Installing an extension in the browser is OK. The goal of this is to allow anot开发者_JS百科her machine to connect to the extension to control a game without needing an intermediary server.

Is this feasible? Is it possible to make a Chrome or Firefox extension open a port to allow for incoming request?


What you are asking for are server sockets. For Chrome the answer is "no", Chrome extensions can only open client connections. Firefox extensions on the other hand can use nsIServerSocket interface to listen for incoming TCP connections on a port. If you use the Add-on SDK you would need to use the chrome package. Something like this:

var {Cc, Ci} = require("chrome");
var socket = Cc["@mozilla.org/network/server-socket;1"]
               .createInstance(Ci.nsIServerSocket);
socket.init(12345, false, -1);
socket.asyncListen({
  onSocketAccepted: function(socket, transport)
  {
    ...
  },
  onStopListening: function(socket, status)
  {
  }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号