Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Packaged App Native Messaging

I have a windows console application and a chrome packaged app that I am trying to get two way communication going with. I've followed the example they have with the python app but I have not had any luck.

I've taken the following steps:

  1. Created this entry in my registry at HKEY_LOCAL_MACHINE\SOFTWARE\Google\NativeMessagingHosts: my.app.name : c:\path\to\my.app.name.json

  2. I've created the json file at that location: { "name": "my.app.name", "description": "Chrome Native Messaging API", "path": "c:\path\to\my.app.name\consoleApp.exe", "type": "stdio", "allowed_origins": [ "chrome-extension://offmjeicniagcebcbclkdlkllfibllfh/" ] }

  3. I have added the following in my packaged app script:

    function connect() {
     var hostName = "my.app.name";
     appendMessage("Connecting to native messaging host <b>" + hostName + "</b>")
     port = chrome.runtime.connectNative(hostName);
     port.onMessage.addListener(onNativeMessage);
     port.onDisconnect.addListener(onDisconnected);        
    }
    
    function appendMessage(text) {
     document.getElementById('messages').innerHTML += "<p>" + text + "</p>";
    }
    
    function onNativeMessage(message) {
      appendMessage("Received message: <b>" + message + "</b>");
    }
    
    function onDisconnected() {
     appendMessage("Failed to connect: " + chrome.runtime.lastError.message);
     port = null;
    }
    

When I click a button that calls the connect function I get this error:

"Invalid native messaging host name specified"

I've tried playing with this every way I can think of but there is just not much documentation or sample code (almost none). Does anyone have any ideas?

thanks

like image 937
Kywillis Avatar asked Oct 20 '22 23:10

Kywillis


1 Answers

Just got it worked! Try to change "path" to "consoleApp.exe" (with all my previous suggestions) and put your app into the same folder as app's manifest. Then check task manager and you will see your process worked. Good luck.

like image 74
Aleksey Isakov Avatar answered Oct 31 '22 14:10

Aleksey Isakov