Google Chrome Extension - Specified Native Messaging Host Not Found
Asked Answered
B

4

11

I created an extension that uses native messaging to a host.

The manifest.json of the extension is:

{
    "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:

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

The main.js file:

    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.

The native application 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).

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.

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.

I need some help in figuring it out, so any help would be usefull!

Thanks

Brennabrennan answered 14/8, 2014 at 8:7 Comment(4)
possible duplicate of Chrome extension native messaging got error:"Specified native messaging host not found."Xerophagy
I'm not sure if there's yet support for HKCU (code.google.com/p/chromium/issues/detail?id=237873). Insert the registry value into HKLM and see if it helps.Ferret
It doesn't work also with the local machine key..Brennabrennan
Did you see my "duplicate" comment above? Can you make a screenshot of your regedit or export the key and quote it here to be sure it's the right format?Xerophagy
C
8

notice that chrome extension listed in allowed_origins has to end with /

wrong code (without /):

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

correct code:

 "allowed_origins": [
    "chrome-extension://acajlpgjiolkocfooiankmegidcifefo/"
  ]
Coburn answered 28/6, 2020 at 4:36 Comment(0)
B
3

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. 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!

Brennabrennan answered 14/8, 2014 at 10:50 Comment(0)
X
0

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.

Xerophagy answered 14/8, 2014 at 8:17 Comment(2)
This also doesn't work when i only give the "abc.exe", or the full pathBrennabrennan
Did you give the full path as C:\\Users\\s8018942\\Desktop\\Extension1\\NativeApp\\abc.exe? Try also the same double-backslash format for the registry key.Xerophagy
D
0

change the name of the native messaging host to be lowercase,

this is mandatory as they mention in the documentation :

enter image description here

visit the : official documentation link

Dicephalous answered 23/11, 2023 at 19:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.