Communication between Chrome javascript and native Windows code

允我心安 提交于 2019-12-12 09:16:17

问题


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.

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.

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


回答1:


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:

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



来源:https://stackoverflow.com/questions/40214431/communication-between-chrome-javascript-and-native-windows-code

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