Is it possible to embed a HTTP server in a Google

2019-01-14 13:38发布

问题:

Do you think it would be possible to embed a HTTP server inside a Google Chrome extension?

I've seen other Google Chrome extensions execute native code and apparrently they do it by using NPAPI, but I have no idea what that is. And it's really freaking me out, as I'm no C++ expert or anything like that. So I feel a little stuck now and that's why I'm asking for help.

Specifically, I want to create an extension for Chrome with features similar to Opera Unite. For those who don't know what I'm talking about: Opera Unite is basically a zero-conf web server bundled with the browser. I don't want to use it for the same things Opera does, but I like the concept.

I was thinking about using something like node.js inside the browser to create a simple web interface to control some stuff in the browser. Think of it as a remote control for the browser. If node.js isn't possible I'd like to use lighthttpd or something similar. The technology really doesn't matter as long as it allows me to receive commands over HTTP.

But how do I take an existing web server and make a NPAPI plugin out of it?

Clarification: I'd like any browser to be able to communicate with my extension. Especially I want mobile devices like Android or the iPhone to be able to remote control the browser. Is there any other way to accomplish that except with a HTTP server?

Another update: I think the easiest way to do this would be to use a relay server on the web like Pusher or some self-created service. But I don't like this approach because it requires constant internet access and because it's a paid service.

Thank you all!

回答1:

Here is info on making a web-server in a Chrome app: https://developers.google.com/live/shows/7320022-5001



回答2:

If you want to do a remote control for the browser, would something like HTML5 WebSockets work for you?

http://www.html5rocks.com/tutorials/websockets/basics/

You can have an external "remote" server that your extension listens to via WebSockets. If you want to host a webserver via extensions. You would need to use NPAPI, there are many C++ libraries out there (Google search) that can do a simple webserver. But I would rather use WebSockets communicate to an external server which will provide you anything you want.

But if you insist, you would need to learn C++, NPAPI, there are many examples online regarding NPAPI.



回答3:

Here is another web server implemented with chrome.socket: https://github.com/kzahel/web-server-chrome. The server example linked to in chrome-app-samples is actually really buggy and will lock up if you e.g. hold down Ctrl-R on a page served by it.