我有一个 Windows 控制台应用程序和一个 chrome 打包的应用程序,我正在尝试使用它们进行双向通信。我已经按照他们在 python 应用程序中使用的示例进行了操作,但我没有任何运气。
我已经采取了以下步骤:
在我的 HKEY_LOCAL_MACHINE\SOFTWARE\Google\NativeMessagingHosts 注册表中创建了这个条目: 我的.app.name : c:\path\to\my.app.name.json
我已经在该位置创建了 json 文件: { "name": "我的.app.name", “描述”:“Chrome 原生消息传递 API”, "路径": "c:\path\to\my.app.name\consoleApp.exe", “类型”:“标准输入输出”, “允许的来源”:[ “chrome-extension://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; }
当我单击一个调用连接函数的按钮时,出现此错误:
“指定的 native 消息传递主机名无效”
我已经尝试过我能想到的所有方法,但没有太多文档或示例代码(几乎没有)。有人有什么想法吗?
谢谢
最佳答案
刚刚成功!尝试将“路径”更改为“consoleApp.exe”(根据我之前的所有建议)并将您的应用程序放入与应用程序 list 相同的文件夹中。然后检查任务管理器,您将看到您的进程有效。祝你好运。
关于javascript - 谷歌打包应用原生消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19255535/