Windows上的Chrome原生消息
我认为它已经在等待答案,但不确定:
Native app does not work in Chrome extension
在Linux上,它工作正常,但在Windows 7和8上,我总是收到错误“未找到指定的本机消息传递主机”. 这是我的注册表(我已尝试使用双反斜杠和HKEY_LOCAL_MACHINE): REG ADD HKEY_CURRENT_USERSOFTWAREGoogleChromeNativeMessagingHostscom.google.chrome.example.echo /ve /d C:UsersChrissDesktopnativeMessaginghostcom.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:UsersChrissDesktopnativeMessaginghostnative-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; } JS片段(从http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extensions/docs/examples/api/nativeMessaging/app/main.js?revision=228976开始): 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(); } 我无法找出问题所在.我的错在哪里? 更新
我也在Windows上遇到这个问题,但是能够让它运行起来.请尝试以下方法:
关于注册表(我在HKLM,但HKCU应该没问题)你应该使用双反斜杠.这是我的.reg文件: [HKEY_LOCAL_MACHINESOFTWAREGoogleChromeNativeMessagingHoststcchrome.native.handler] @="G:ExtChromeExtensionNativemanifest.json" >使用小写字母和仅3个部分保留本机进程的名称 – 即com.google.chrome.这听起来很奇怪,但这就是它对我有用的方式…… 这是我的清单,例如: { "name": "chrome.native.handler","description": "BlaBla helper process","path": "chrome.native.handler.exe","allowed_origins": [ "chrome-extension://eoknpfoeckmeidbmbfoklejkppcnlfdm/" ] } 顺便说一下,你没有正确处理回应.您应该以“本机字节顺序”发送消息长度 – 您正在执行的操作不适用于较大的消息.相反,你可以这样做: cout.write((char*)&resSize,4); cout.write(responseBuf,resSize); 希望这可以帮助 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |