Chrome浏览器JavaScript与原生Windows代码之间的通信 [英] Communication between Chrome javascript and native Windows code

查看:524
本文介绍了Chrome浏览器JavaScript与原生Windows代码之间的通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Chrome上运行的Web应用程序与Windows上的本机代码之间建立沟通渠道。当JS请求并从本机代码传回结果时,我需要运行本机代码。这个环境是完全管理的,所以我可以设置信任和组策略等。

I need to have a communication channel between my web application that runs on Chrome, and a native code on Windows. I need to run a native code when JS requests and pass the results back from native code. The environment is totally managed so I can set trusts and group policies, etc.

我可以考虑准备一个本地运行的小型Web服务(并允许CORS)这项服务来自JavaScript,但在这种情况下,我需要永远运行此代码。

I can think of preparing a small web service that runs locally (and allows CORS) and call this service from javascript, but in this case i need to run this code forever.

任何建议都会非常有帮助。如果可能的话,我可以尝试Windows注册表写入/读取,管道,共享内存,MMF或任何其他方式来做到这一点。

Any advices will be very helpful. If it is possible i can try Windows registry write/read, pipes, shared memory, MMF or any other way to do it.

谢谢

Thanks

推荐答案

有一种方法可以在不使用扩展的情况下与本地进程进行通信。 Websockets并不局限于与网页相同的域进行通信,它们可以与本地主机上的WebSocket服务器进行通信。您必须将自己的本地代码包装到WebSocket服务器中,但可使用库。

There's a way to communicate with local processes without using an extension. Websockets aren't restricted to communicating with the same domain as the web page, they can communicate with a WebSocket server on localhost. You have to wrap your native code in a WebSocket server, libraries are available for that though.

另一种方法是本机消息传递,但它需要浏览器扩展:

Another method is Native Messaging, but it requires a browser extension:


本地消息传递使WebExtension能够与安装在用户计算机上的
原生应用程序交换消息。

Native messaging enables a WebExtension to exchange messages with a native application installed on the user's computer.

https: //developer.mozilla.org/en-US/Add-ons/WebExtensions/Native_messaging
https://developer.chrome.com/extensions/nativeMessaging

这篇关于Chrome浏览器JavaScript与原生Windows代码之间的通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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