使用Sublime Text插件中的“Chrome原生消息” [英] Use 'Chrome Native Messaging' from Sublime Text plugin
问题描述
Google甚至提供了一个例子来说明如何使用pythonhost-app来执行此操作: https://chromium.googlesource.com/chromium/src/+/master/chrome/common / extensions / docs / examples / api / nativeMessaging / host / native-messaging-example-host
我想用这种技术在Sublime文本插件(python)和一个Chrome扩展。
- 有没有人有这方面的经验,或者知道一些我可以看的开源ST插件
- 你在
名字
和路径
中写什么?清单文件?可以使用stdin
和标准输出
与崇高文本插件中的chrome进行通信,或者在您编写插件时是否存在限制?
对不起看起来像一个愚蠢的问题,我通常做web,而不是本地开发。 解决方案
原生消息传递无法连接到任意进程,因为:
- 该流程必须使用指定协议通过
stdin
将断开连接。我怀疑在这种情况下,Sublime插件可以改变Sublime的行为。 - Chrome将始终运行指定主机的新实例;它不能连接到现有的主机。
因此,您假设的Native主机必须是独立的进程,可以独立于Sublime重新启动,以某种方式与Sublime交谈。
您实际上并不需要本地消息传递协议。另一种方法是使用WebSocket:Sublime插件可以充当本地主机上的WebSocket服务器,并且扩展可以连接到该服务器。作为这种体系结构的一个示例,请参阅 GhostText 。
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 thepath
of the manifest file? The name and path of the sublime text application? - Can I use
stdin
andstdout
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.
Native messaging cannot connect to an arbitrary process, because:
- 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. - 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.
这篇关于使用Sublime Text插件中的“Chrome原生消息”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!