【发布时间】:2013-10-15 20:07:16
【问题描述】:
我有一个 Windows 控制台应用程序和一个 chrome 打包应用程序,我正在尝试通过两种方式进行通信。我已经按照他们使用 python 应用程序的示例进行操作,但我没有任何运气。
我已采取以下步骤:
在我的注册表 HKEY_LOCAL_MACHINE\SOFTWARE\Google\NativeMessagingHosts 中创建了此条目: my.app.name : c:\path\to\my.app.name.json
我已经在那个位置创建了 json 文件: { "name": "my.app.name", "description": "Chrome 原生消息 API", "路径": "c:\path\to\my.app.name\consoleApp.exe", “类型”:“标准输入法”, “允许的来源”:[ “铬扩展://offmjeicniagcebcbclkdlkllfibllfh/” ] }
-
我在打包的应用脚本中添加了以下内容:
function connect() { var hostName = "my.app.name"; appendMessage("Connecting to native messaging host <b>" + hostName + "</b>") port = chrome.runtime.connectNative(hostName); port.onMessage.addListener(onNativeMessage); port.onDisconnect.addListener(onDisconnected); } function appendMessage(text) { document.getElementById('messages').innerHTML += "<p>" + text + "</p>"; } function onNativeMessage(message) { appendMessage("Received message: <b>" + message + "</b>"); } function onDisconnected() { appendMessage("Failed to connect: " + chrome.runtime.lastError.message); port = null; }
当我单击一个调用连接函数的按钮时,我收到此错误:
“指定的本地消息传递主机名无效”
我已经尝试了所有我能想到的方法,但没有太多文档或示例代码(几乎没有)。有人有什么想法吗?
谢谢
【问题讨论】:
-
来自user3174625的评论:你是如何在 C# 中接收消息的?
标签: javascript windows google-chrome google-chrome-app chrome-native-messaging