Use 'Chrome Native Messaging' from Sublime

2019-01-24 18:40发布

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条回答
再贱就再见
2楼-- · 2019-01-24 19:32

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.

查看更多
登录 后发表回答