我認爲它已經等待答案,但不知道本地消息:Native app does not work in Chrome extension
在Linux上,它工作正常,但在Windows 7和8,我總是得到一個錯誤「指定的本地消息主機未找到「。Chrome Windows版
這是我註冊表(我已經帶有雙反斜線與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
manifest.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/"
]
}
本機消息傳遞的示例-host.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();
}
我找不出什麼問題。我的錯在哪裏?
更新
與Procces監視器監視註冊表後。我發現chrome.exe在64位密鑰中搜索密鑰。現在,我可以看到沒有缺少相關的註冊表項,但仍然出現錯誤。
謝謝您的幫助!由manifest.json中的絕對路徑字符串引起的問題。 – Chriksz
請幫助爲什麼這不起作用,但你的工作? http://stackoverflow.com/q/26021106/285594 – YumYumYum
親愛的@ Spike0xffI有一個問題:什麼是本機信息的類型?它是一個Chrome應用程序或擴展? –