What is Native Messaging between applications and how does it work?

后端 未结 1 1607
醉话见心
醉话见心 2020-12-31 21:00

The Chrome developer docs refer to something called Native Messaging to communicate with other desktop applications directly from the Chrome extension or app.

相关标签:
1条回答
  • 2020-12-31 21:48

    An extension can only communicate with a native desktop application if that application is registered as a "native messaging host". This means that there must be some manifest file at a pre-defined, platform-specific location that declares that the application has "native messaging" capabilities and which extensions are allowed to communicate with this native messaging host.

    So, by default, it is extremely unlikely that any of your desktop apps support native messaging. This term is a specific to Chrome/Chromium, and might not be understood by developers who are not familiar with Chrome/Chromium. Though every competent developer should be able to get native messaging to work after reading the documentation of native messaging.

    Currently, the only supported way of communicating with native applications is through the standard input and output pipes (stdin / stdout) via a simple yet strict protocol. If the desktop app has a command-line interface, then you can easily write a proxy application that serves as a native messaging host and interacts with the desktop application. It is essentially the bridge between your Chrome extension and some other application. This proxy application can be written in any language that supports stdin/stdout, and it does not require any cooperation from the original developers of the desktop app.

    The native messaging protocol is the same across all platforms, but you have to take the endianness of the system into account, and the locations of the manifest file also platform-dependent.

    0 讨论(0)
提交回复
热议问题