-->

Chrome原始消息 - 为什么我会收到错误“找不到指定的本地消息主机”?(Chrome Nativ

2019-10-21 12:31发布

据Chrome原始消息文档成功调用connectNative()返回一个端口,通过它可以将消息发布到本机应用程序(在Mac应用程序)。 在我的情况nativeConnect()不会在我的情况下返回一个有效的端口,但onDisconnected()的调用听者几乎立即被解雇。 每当监听器被触发它打印“lastError”属性设置为浏览器的控制台,这给:

Specified native messaging host not found.

为什么这样做呢? 该生产味精的听众看起来是这样的:

function onDisconnected() {
  console.log("Inside onDisconnected(): " + chrome.runtime.lastError.message);
  port = null;
}

有一个关于向文档(底部此特定错误一整节的本地消息传递 ),以及拟议的补救说,无论清单文件被命名,放置或定义(JSON)不正确,否则主机应用程序未命名或定位在清单说它应该是。 该医生说connectNative()将“启动一个单独的进程主机”,但活动监视器没有给出证据表明,本地主机的应用程序正式启动。

我叫connectNative()如下:

chrome.runtime.onMessageExternal.addListener(

  function(request, sender, sendResponse) {
    //var imgdata = JSON.stringify(request.imgdata);
    //process it somehow here

    port = chrome.runtime.connectNative("com.allinlearning.nmhforbrowserextension");

    if (port)
    {
       console.log("connectNative() returned a non-null port");

       port.onMessage.addListener(onNativeMessage);
       port.onDisconnect.addListener(onDisconnected);
    }
});

我的本地主机清单文件位于正确的文件夹为每个文档,分析细如JSON,看起来像:

{
  "name": "com.allinlearning.nmhforbrowserextension",
  "description": "Manifest for native messaging host for Google browser extension",
  "path": "/Users/mycomputer1/Documents/nmhost.app",
  "type": "stdio",
  "allowed_origins": ["chrome-extension://gldheanjpgopipommeingjlnoiamdfol/"]
}

Chrome扩展需要一个清单还,直到我得到的权限部分中,右键我无法从connectNative()得到一个非空口回来,所以我敢肯定这是目前正确的:

"permissions": [
               "nativeMessaging",
                "tabs",
                "activeTab",
                "background",
                "http://*/", "https://*/"
                ]

更新:

想通了如何启动从Mac的终端的Chrome浏览器与标志使更多的“详细”日志查看。 然后,当我跑的事情,我注意到这样的输出:

[21285:38915:1231/164417:ERROR:native_process_launcher.cc(131)] Can't find manifest for native messaging host com.allinlearning.nmhforbrowserextension

很清楚它无法找到主机清单,但为什么?

Answer 1:

对于谷歌Chrome,对于清单文件中的全系统目录的是:

~/Library/Application Support/Google/Chrome/NativeMessagingHosts/

用户特定的安装路径是:

~/Library/Application Support/Chromium/NativeMessagingHosts/

(当前记录的Mac路径不正确( 补丁 )。在这些路径install.sh (来自的例子 )的文档中是正确的,虽然)。



文章来源: Chrome Native Messaging — Why am I receiving a “Specified native messaging host not found” error?