Proper way to listen as TCP server in Chrome extension

泄露秘密 提交于 2019-12-21 11:26:09

问题


I want to create a TCP server and listen on it. I need access to the tab content, so I need a chrome extension. Sadly, only chrome apps can create TCP servers.

Is it a valid/good concept to create a TCP server in a chrome app and let the app communicate with an extension (is this even possible?)?

If not, what would be my alternatives? The only idea I have is to change from server model to client model and let the extension connect to an external server. This solution would be poor in my situation, so I try to avoid it as best as I can.

What I want to achieve is that I can build a chrome extension that modifies/refreshes content with remote access (nothing malicious). External programs should be able to connect to the extension (or: the app) and send their commands to it.


回答1:


Yes it's a good idea.

1°) You should create a Chrome App Web Server (based on https://github.com/GoogleChrome/chrome-app-samples/tree/master/samples/webserver for example, or any other HTTP s)

2°) Then you should request it from any javascripted web page via XmlHttpRequest.

+++: No need for Chrome Extension. Should work with any modern browser on Windows / Mac / Linux with Chrome 33+ installed.



来源:https://stackoverflow.com/questions/25715457/proper-way-to-listen-as-tcp-server-in-chrome-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!