Google chrome extension 未捕获类型错误:无法调用方法';connectNative';在本机消息传递应用程序中

Google chrome extension 未捕获类型错误:无法调用方法';connectNative';在本机消息传递应用程序中,google-chrome-extension,google-api,google-apps,google-chrome-app,chrome-native-messaging,Google Chrome Extension,Google Api,Google Apps,Google Chrome App,Chrome Native Messaging,我正在使用本机消息应用程序。我创建了以下文件 1。C++ CONOLE APP 2.JS文件 3.manifet文件 我已经创建了这样的注册表项 现在我在port=chrome.runtime.connectNative(主机名)行中遇到错误。我注意到chrome.runtime本身未定义。请告诉我是否遗漏了任何内容 Manifest.jason function connect() { //var m1 = chrome.runtime.getManifest(); var host

我正在使用本机消息应用程序。我创建了以下文件

1。C++ CONOLE APP 2.JS文件 3.manifet文件 我已经创建了这样的注册表项

现在我在port=chrome.runtime.connectNative(主机名)行中遇到错误。我注意到chrome.runtime本身未定义。请告诉我是否遗漏了任何内容

Manifest.jason

function connect() {
  //var m1 = chrome.runtime.getManifest();
  var hostName = "NM1";
  var t1 = chrome;
  appendMessage("Connecting to native messaging host <b>" + hostName + "</b>")    

  port = chrome.runtime.connectNative(hostName);
  port.onMessage.addListener(onNativeMessage);
  port.onDisconnect.addListener(onDisconnected);
  updateUiState();
}
函数连接(){
//var m1=chrome.runtime.getManifest();
var hostName=“NM1”;
var t1=铬;
appendMessage(“连接到本机消息传递主机”+主机名+“”)
port=chrome.runtime.connectNative(主机名);
port.onMessage.addListener(onNativeMessage);
端口.onDisconnect.addListener(onDisconnected);
UpdateUstate();
}
main.js

function connect() {
  //var m1 = chrome.runtime.getManifest();
  var hostName = "NM1";  
  appendMessage("Connecting to native messaging host <b>" + hostName + "</b>")

  port = chrome.runtime.connectNative(hostName);
  port.onMessage.addListener(onNativeMessage);
  port.onDisconnect.addListener(onDisconnected);
  updateUiState();
}
函数连接(){
//var m1=chrome.runtime.getManifest();
var hostName=“NM1”;
appendMessage(“连接到本机消息传递主机”+主机名+“”)
port=chrome.runtime.connectNative(主机名);
port.onMessage.addListener(onNativeMessage);
端口.onDisconnect.addListener(onDisconnected);
UpdateUstate();
}

如果扩展中没有运行javascript,则可能会出现此错误。chrome运行时不存在于此之外,如果您通过注入运行javascript,则运行时不存在于此

此外,不要忘记在manifest.json中包含nativeMessaging权限

"permissions": [
    "nativeMessaging"
]

如果没有在扩展中运行javascript,则可能会出现此错误。chrome运行时不存在于此之外,如果您通过注入运行javascript,则运行时不存在于此

此外,不要忘记在manifest.json中包含nativeMessaging权限

"permissions": [
    "nativeMessaging"
]

看起来您意外地在main.js中复制了两次,而不是在manifest.json中复制。看起来您意外地在main.js中复制了两次,而不是在manifest.json中复制。