Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/472.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么我会收到Chrome本机消息;找不到指定的本机消息传递主机。";?_Javascript_Json_Windows_Google Chrome_Chrome Native Messaging - Fatal编程技术网

Javascript 为什么我会收到Chrome本机消息;找不到指定的本机消息传递主机。";?

Javascript 为什么我会收到Chrome本机消息;找不到指定的本机消息传递主机。";?,javascript,json,windows,google-chrome,chrome-native-messaging,Javascript,Json,Windows,Google Chrome,Chrome Native Messaging,我已经研究这个有一段时间了,我想不出来。我已阅读,但我一直从扩展中获取“未找到指定的本机消息传递主机”错误 注册表指向的清单: { "name": "com.fordcars.chromekeys", "description": "ChromeKeys description", "path": "C:\Users\fordcars\Desktop\Development\ChromeKeys\Debug\ChromeKeys.exe", "type": "stdio",

我已经研究这个有一段时间了,我想不出来。我已阅读,但我一直从扩展中获取“未找到指定的本机消息传递主机”错误

注册表指向的清单:

{
  "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);
请记住,我一连接native()就会收到错误。我在扩展清单中具有“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

谢谢

反斜杠是JSON中的转义字符。您必须在清单中使用两个反斜杠作为路径分隔符:

//坏:
“路径”:“C:\Users\fordcars\Desktop\Development\ChromeKeys\Debug\ChromeKeys.exe”,
//好:
“路径”:“C:\\Users\\fordcars\\Desktop\\Development\\ChromeKeys\\Debug\\ChromeKeys.exe”,
我强烈建议您学习如何按照中所述进行调试,因为如果您这样做,您将看到更详细的错误消息:

找到清单,但不是本机消息传递主机com.fordcars.chromekeys的二进制文件。清单中指定的主机路径:C:UsersordcarsDesktopDevelopmentChromeKeysDebugChromeKeys.exe


即使不看错误日志,如果您遵循错误消息的要点,您也会注意到和您的之间的差异(即拼写错误的反斜杠)。

好吧,您真的应该再次阅读文档。是的,我只是从JSON验证程序那里得到的,但肯定会查看Chrome日志的输出