【发布时间】:2019-03-04 02:52:52
【问题描述】:
我下载了官方 Chrome nativeMessaging example 进行测试。
为此,我从 chrome://extensions 安装了该应用程序,方法是选择 Load Unpacked。到目前为止没有问题。
然后我安装了主机。我使用的是 Windows 7,所以我运行了 install_host.bat,它声称“操作已成功完成”。但是,当我转到 chrome://apps/ 并单击“连接”按钮时,出现此错误:
Failed to connect: Native host has exited.
发生这种情况有什么原因吗?重新启动 Chrome 并没有解决问题,卸载然后重新安装主机程序也没有解决问题。
(我注意到 native-messaging-example-host.bat 需要 Python 2,所以我对其进行了修改以显式运行 Python 2。如果我从命令行运行 native-messaging-example-host.bat,它会弹出一个带有 GUI 的小示例程序,似乎可以正常工作。)
【问题讨论】:
-
我可以确认已创建以下注册表项:HKEY_CURRENT_USER\Software\Google\Chrome\NativeMessagingHosts\com.google.chrome.example.echo。它的值指向下载示例中的 ...\host\com.google.chrome.example.echo-win.json 文件。
-
确保
python.exe在 PATH 中或编辑 native-messaging-example-host.bat 以指向正确的可执行文件。例如,我使用了py -2。 -
它在路径中。我还尝试使用绝对路径直接指向 Python 2 可执行文件。
-
因为它对我有用,所以这个例子可能是正确的。尝试寻找有关如何调试 nativeMessaging(如 --enable-logging 等)的答案/文章。
-
不需要在后台手动运行主机吧?当你点击连接时,应用程序应该会自动启动主机,对吧?
标签: google-chrome google-chrome-extension chrome-native-messaging