如何将Chrome扩展作为Web套接字服务器运行? [英] How to run a chrome extension as a web socket server?

查看:445
本文介绍了如何将Chrome扩展作为Web套接字服务器运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望将chrome浏览器用作
数字标牌用途的软件技术平台。为了强制chrome浏览器接收和执行任何
自定义的自定义命令(例如创建一个新标签并查询
某些网页/ url的内容),我需要运行chrome浏览器一个服务器
正在监听某个网络端口。



使用websockets,server.io等的最佳方式/技术是什么?

解决方案

NPAPI 是唯一的方法来做你想做的事情,而不是从源头上彻底修改和编译Chromium。如果控制Chrome的客户端在浏览器中,那么将WebSocket库打包为NPAPI插件可能是您最好的选择。如果你的客户端是一个桌面应用程序,打包一个普通的TCP库应该是足够的。



然而,NPAPI的学习曲线相当陡峭,所以我不推荐使用它如果你能帮助它。如果可能的话,只需让Chrome建立一个连接中央服务器的连接(例如使用Socket.io)即可。您的客户端也可以连接到该服务器并使用它将命令转发到您想远程控制的Chrome实例。



因此,而不是:



<控制客户端> ---> [Chrome]



您可以使用:

[Chrome] ---> [myserver.example.net]< --- [控制客户端]



如果您的系统要求独立于互联网(例如,Chrome并不总是可以访问特定的外部服务器,如myserver.example.net,但仍然需要接受本地网络上的客户端),那么您可以在与Chrome浏览器相同的机器上运行中间服务器你正在控制。


I would like to use the chrome browser as a software technical platform for digital signage purposes. To force the chrome browser to receive and execute any self-defined custom commands (e.g. create a new tab and inquire the content of a certain web-page/url) I need to run the chrome browser as a server listening to a certain network port.

What is the best way/technology to use websockets, server.io, etc?

解决方案

NPAPI is the only way to do what you want, short of drastically modifying and compiling Chromium from source. If the client that controls Chrome is in a browser, then packaging a WebSocket library as an NPAPI plugin is probably your best bet. If your client is a desktop application, packaging a plain TCP library should be sufficient.

However, NPAPI has quite a steep learning curve, so I don't recommend using it if you can help it. If possible, just have Chrome establish a constant connection to a central server (using, e.g., Socket.io). Your client can also connect to that server and use it to forward commands to the Chrome instance that you want to remotely control.

So, instead of:

[controlling client] ---> [Chrome]

You could use:

[Chrome] ---> [myserver.example.net] <--- [controlling client]

If your system requirements mandate independence from the Internet (i.e. Chrome won't always have access to a specific external server like myserver.example.net, but must still accept clients on the local network), then you could run the intermediate server on the same machine as the Chrome browser that you're controlling.

这篇关于如何将Chrome扩展作为Web套接字服务器运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆