How can I send a message from Google Chrome extension to desktop application?

痞子三分冷 提交于 2019-12-17 20:19:36

问题


I have a Windows desktop application which must work in collaboration with my Chrome extension.

Can I send a message to my desktop app somehow from Google Chrome extension?

Which IPC objects can I use?


回答1:


I see three options:

  1. You could use the internet. You can have a remote service that both the chrome extension and your desktop app talk to, to communicate.
  2. You could have your desktop app have a simple server built into it so that the chrome extension can make local http requests to it to communicate with it.
  3. Use the Google NPAPI plugin functionality to have full access to the computer. Now deprecated



回答2:


These days you would use Chrome's native messaging API to send the message from your extension to a native messaging host. The latter can be a "real" executable that then passes the message on to your desktop application.

Documentation: http://developer.chrome.com/extensions/messaging#native-messaging-host




回答3:


This almost certainly requires a custom NPAPI plugin and cannot be done with the basic extension API. NPAPI development is fairly daunting and outside my area of expertise, but feel free to read over Google's documentation on the subject.

As an alternative, perhaps you can have your desktop application poll the internals of the extension. For example, the extension's could have a file in its sandboxed filesystem where it leaves messages for the desktop application to find. This approach is suboptimal, since it requires polling instead of pushing, but it does save you the hassle of coding an NPAPI plugin.




回答4:


chrome extension has a native massage api to communicate to native process,

see here:

https://developer.chrome.com/apps/nativeMessaging



来源:https://stackoverflow.com/questions/12056380/how-can-i-send-a-message-from-google-chrome-extension-to-desktop-application

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