我已经为此工作了一段时间,我无法弄清楚。我已阅读Chrome Native Messaging 文档,但我不断收到“未找到指定的本机消息传递主机”。来自扩展的错误。
注册表指向的清单:
{
"name": "com.fordcars.chromekeys",
"description": "ChromeKeys description",
"path": "C:\Users\fordcars\Desktop\Development\ChromeKeys\Debug\ChromeKeys.exe",
"type": "stdio",
"allowed_origins": [
"chrome-extension://pdkakljppghagmaoijbpicogfdbodpbc"
]
}
扩展脚本:
// Event page
var nativeName = "com.fordcars.chromekeys";
var nativePort = chrome.runtime.connectNative(nativeName);
function nativeDataReceived(data)
{
// Not used
}
function nativeDisconnected()
{
console.log("Native program disconnected. Error: " + chrome.runtime.lastError.message);
}
nativePort.onMessage.addListener(nativeDataReceived);
nativePort.onDisconnect.addListener(nativeDisconnected);
请记住,一旦我 connectNative(),我就会收到错误消息。我的扩展清单中有“nativeMessaging”权限。
注册表:
Subkey: HKEY_CURRENT_USER\Software\Google\Chrome\NativeMessagingHosts\com.fordcars.chromekeys
Value name: (Default)
Value: C:\Users\fordcars\Desktop\Development\ChromeKeys\Debug\nativeManifest.json
调试: 我做了一些调试,发现如果我将 connectNative nativeName 从com.fordcars.chromekeys 更改为其他任何内容,我仍然会收到相同的错误,因此要么找不到注册表项,要么/并且我没有有一个好的 manifest.json。
谢谢!