我认为它已经在等待答案,但不确定:本机应用程序在 Chrome 扩展中不起作用在
Linux 上,它工作正常,但在 Windows 7 和 8 上我总是收到错误“未找到指定的本机消息传递主机”。
这是我的注册表(我已经尝试过使用双反斜杠和 HKEY_LOCAL_MACHINE):
REG ADD HKEY_CURRENT_USER\SOFTWARE\Google\Chrome\NativeMessagingHosts\com.google.chrome.example.echo /ve /d C:\Users\Chriss\Desktop\nativeMessaging\host\com.google.chrome.example.echo-win.json
清单.json:
{
// Extension ID: knldjmfmopnpolahpmmgbagdohdnhkik
"key":"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDcBHwzDvyBQ6bDppkIs9MP4ksKqCMyXQ/A52JivHZKh4YO/9vJsT3oaYhSpDCE9RPocOEQvwsHsFReW2nUEc6OLLyoCFFxIb7KkLGsmfakkut/fFdNJYh0xOTbSN8YvLWcqph09XAY2Y/f0AL7vfO1cuCqtkMt8hFrBGWxDdf9CQIDAQAB",
"name": "Native Messaging Example",
"version": "1.0",
"manifest_version": 2,
"description": "Send a message to a native application.",
"browser_action": {
"default_title": "Test Extension",
"default_popup": "main.html"
},
"icons": {
"128": "icon-128.png"
},
"permissions": [
"nativeMessaging"
]
}
com.google.chrome.example.echo-win.json:
{
"name": "com.google.chrome.example.echo",
"description": "Chrome Native Messaging API Example Host",
"path": "C:\Users\Chriss\Desktop\nativeMessaging\host\native-messaging-example-host.exe",
"type": "stdio",
"allowed_origins": [
"chrome-extension://knldjmfmopnpolahpmmgbagdohdnhkik/"
]
}
本机消息传递示例主机.exe:
int main(int argc, char* argv[]) {
// Define our message
std::string message = "{\"text\": \"This is a response message\"}";
// Collect the length of the message
unsigned int len = message.length();
// We need to send the 4 bytes of length information
std::cout
<< char(((len >> 0) & 0xFF))
<< char(((len >> 8) & 0xFF))
<< char(((len >> 16) & 0xFF))
<< char(((len >> 24) & 0xFF));
// Now we can output our message
std::cout << message;
return 0;
}
function connect() {
var hostName = "com.google.chrome.example.echo";
appendMessage("Connecting to native messaging host <b>" + hostName + "</b>")
port = chrome.runtime.connectNative(hostName);
port.onMessage.addListener(onNativeMessage);
port.onDisconnect.addListener(onDisconnected);
updateUiState();
}
我无法找出问题所在。我的错在哪里?
update
在使用 Procces Monitor 监控注册表之后。我发现 chrome.exe 在 64 位密钥中搜索密钥。现在我可以看到没有丢失相关的注册表项,但我仍然收到错误消息。