Chrome nativeMessaging 示例在 Windows 上失败

Chrome nativeMessaging example fails on Windows

我下载了官方ChromenativeMessaging example来测试一下

为此,我从 chrome://extensions 安装了应用程序,方法是选择“加载解压”。目前没有问题。

然后我安装了主机。我正在使用 Windows 7,所以我 运行 install_host.bat,声称 "The operation completed successfully." 但是,当我转到 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 的自己的小示例程序,并且似乎可以正常工作。)

原来我在通往主机可执行文件的路径中使用了非标准字符。这对任何其他程序来说都不是问题,但我猜 Chrome 的本地消息传递 API 不喜欢它。

顺便说一句,关于设置这个例子的文档几乎不存在,但是这个堆栈溢出 link 有一些有用的信息:Chrome Extension NativeMessaging 'connectNative' undefined