Use 'Chrome Native Messaging' from Sublime Text plugin

柔情痞子 提交于 2019-12-18 04:23:17

问题


With 'Native Messaging' it should be possible to communicate between a chrome extension and a native app. https://developer.chrome.com/extensions/nativeMessaging

Google even provides an example for how to do this with a python "host"-app: https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/docs/examples/api/nativeMessaging/host/native-messaging-example-host

I wanted to use this technique to communicate between a Sublime Text plugin (python) and an Chrome extension.

  • Does anybody have experience with this or maybe know some open source ST plugin that I can look at?
  • What do you write in the name and the path of the manifest file? The name and path of the sublime text application?
  • Can I use stdin and stdout to communicate with chrome from the sublime text plugin or are there restrictions to this when you write a plugin?

Sorry if this seems like a silly question, I usually do web, not native development.


回答1:


Native messaging cannot connect to an arbitrary process, because:

  1. The process must be talking over stdin using the specified protocol, or Chrome will break the connection off. I doubt Sublime plugins can alter Sublime's behavior in this case.
  2. Chrome will always run a new instance of the specified host; it cannot connect to an existing one.

So your hypothetical Native host must be a separate process, that can be restarted independently of Sublime and somehow talk to Sublime.

You don't actually need the Native Messaging protocol here. An alternative route is to use WebSockets: a Sublime plugin can act as a WebSocket server on localhost, and an extension can connect to that. See GhostText as an example of such architecture.



来源:https://stackoverflow.com/questions/29591150/use-chrome-native-messaging-from-sublime-text-plugin

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