简体   繁体   English

Google Chrome 扩展程序 - 未找到指定的本机消息传递主机

[英]Google Chrome Extension - Specified Native Messaging Host Not Found

I created an extension that uses native messaging to a host.我创建了一个使用本地消息传递到主机的扩展。

The manifest.json of the extension is:扩展的 manifest.json 是:

{
    "manifest_version": 2,
    "version": "1.0",
    "name": "Native Messaging Example",
    "description": "Send a message to a native application",
    "permissions": [
        "nativeMessaging"
    ],
    "browser_action": {
        "default_popup": "popup.html"
    }
}

The popup.html: popup.html:

    <html>
        <head>
            <script src="./main.js"></script>
        </head>
        <body>
            <button id="buttonToPress">Press</button>
        </body>
    </html>

The main.js file: main.js 文件:

    var port = null;

    function connect() {

        port = chrome.runtime.connectNative('com.google.chrome.example.echo');

        port.onMessage.addListener(function(message) {

            alert(message);

            port.disconnect();
        });

        port.onDisconnect.addListener(function() {

            port = null;

            alert(chrome.runtime.lastError.message);
        });

        var message = {
            'filePath': 'C:\\Users\\username\\Desktop\\themes\\Wallpaper\\Architecture\\img13.jpg'
        };

        port.postMessage(message);
    }

    document.addEventListener('DOMContentLoaded', function() {
        document.getElementById('buttonToPress').addEventListener('click', connect);
    });

I have a native application abc.exe .我有一个本机应用程序abc.exe

The native application manifest.json:本机应用程序 manifest.json:

    {
        "name": "com.google.chrome.example.echo",
        "description": "Chrome Native Messaging API Example Host",
        "path": "./abc.exe",
        "type": "stdio",
        "allowed_origins": [
            "chrome-extensions://fegpbklgdffjmfjmhknpmgepbddbcghk/"
        ]
    }

In the registrey, The Default Value of HKEY_CURRENT_USER\\Software\\Google\\Chrome\\NativeMessagingHosts\\com.google.chrome.example.echo is C:\\Users\\username\\Desktop\\Extension1\\NativeApp\\manifest.json (This is where the manifest file is physically exists).HKEY_CURRENT_USER\\Software\\Google\\Chrome\\NativeMessagingHosts\\com.google.chrome.example.echoHKEY_CURRENT_USER\\Software\\Google\\Chrome\\NativeMessagingHosts\\com.google.chrome.example.echo默认值C:\\Users\\username\\Desktop\\Extension1\\NativeApp\\manifest.json (这是清单文件实际存在)。

The problem is, that each time i run it, it keep saying: 'Specified Native Messaging Host Not Found' ... I rechecked my code and it seems to be fine, just like the google's guide of native messaging.问题是,每次我运行它时,它一直说: “未找到指定的本地消息传递主机” ......我重新检查了我的代码,它似乎没问题,就像谷歌的本地消息传递指南一样。 The error that logged in the debugger's console is: 'Uncaught Error: Attempting to use a disconnected port object' , which i don't know why it keeps happening.调试器控制台中记录的错误是: 'Uncaught Error: Attempting to use a disconnected port object' ,我不知道为什么它一直发生。

Also, after the chrome.runtime.connectNative , the .exe doesn't start (after seeing in the task manager), and it just seems likes there something that not code-related, but more likely to be in the configuration.此外,在chrome.runtime.connectNative ,.exe 不会启动(在任务管理器中看到后),它似乎只是喜欢与代码无关的东西,但更有可能在配置中。

I need some help in figuring it out, so any help would be usefull!我需要一些帮助来解决这个问题,所以任何帮助都会有用!

Thanks谢谢

notice that chrome extension listed in allowed_origins has to end with /请注意,allowed_origins 中列出的 chrome 扩展必须以 / 结尾

wrong code (without /):错误代码(没有 /):

 "allowed_origins": [
    "chrome-extension://acajlpgjiolkocfooiankmegidcifefo"
  ]

correct code:正确的代码:

 "allowed_origins": [
    "chrome-extension://acajlpgjiolkocfooiankmegidcifefo/"
  ]

I'm not sure relative paths work for Native Host manifests.我不确定相对路径是否适用于本机主机清单。

In any case, if you compare with the example in the docs , you're using the wrong kind of slash.无论如何,如果您与docs 中示例进行比较,那么您使用的斜杠类型是错误的。

I've managed to work the solution out.我已经设法解决了这个问题。 I've created the whole pack once again from scratch and set the name of the host application in lowercase.我从头开始再次创建了整个包,并将主机应用程序的名称设置为小写。 Also i set the key in the registry in 'CURRENT_USER' and it worked well.此外,我在“CURRENT_USER”中设置了注册表中的键,它运行良好。 I guess that maybe the host name should be in lowercase but other than this I don't know where I went wrong.我想也许主机名应该是小写的,但除此之外我不知道我哪里出错了。 Thanks alot guys for the help!!!非常感谢大佬的帮助!!! I Appreciate it!我很感激!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我得到Chrome Native Messaging“找不到指定的本地消息传递主机。”? - Why am I getting Chrome Native Messaging “Specified native messaging host not found.”? Chrome 本地消息传递 — 为什么我会收到“未找到指定的本地消息传递主机”错误? - Chrome Native Messaging — Why am I receiving a “Specified native messaging host not found” error? Chrome:本机消息传递错误:禁止访问指定的本机消息传递主机 - Chrome : Native messaging Error: Access to the specified native messaging host is forbidden 为Chrome扩展程序指定本机消息传递主机 - Specifying Native Messaging Host for Chrome extension 找不到Google扩展的本机消息传递主机 - Google extensions Native messaging host not found 为什么带有UI的chrome扩展的本机消息传递主机会挂起? - Why would a native messaging host for a chrome extension with a UI hang? Chrome Native Messaging Chrome扩展程序 - Chrome Native Messaging Chrome Extension 未找到本机消息传递主机的清单 - Manifest for native messaging host not found Chrome扩展原生邮件同步 - Chrome extension Native messaging synchronization 如何修复Chrome浏览器扩展程序中的本机主机已退出错误-本机消息传递 - How to fix Native Host Has Exited error in Chrome browser extension — Native Messaging
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM