Problem with relative path to native messaging host manifest on Windows

5,902 views
Skip to first unread message

Aki Kanerva

unread,
Jan 23, 2014, 8:14:41 AM1/23/14
to chromium-...@chromium.org
Hi guys,

I'm developing an extension that uses a native messaging host. I have everything running smoothly, but have a problem regarding installation. I can't find a way to use a relative path to the manifest file in the Windows registry key.

Based on what I've seen, the preference is to bundle the native host executable with the extension itself, then use an installer to register the path to the manifest. Therefore, it should be simple enough to set the key value to refer to a file inside the extension package:
  host\host_manifest.json
But this produces an error message saying "Specified native messaging host not found".

It works if I use the absolute path:
  C:\Users\<USERNAME>\AppData\Local\Google\Chrome\User Data\Default\Extensions\<EXTENSION>\<VERSION>\host\host_manifest.json

However, there are many variables in that path: account name and Chrome profile folder, not to mention the browser name (Chrome, Chromium or something else entirely). Is it even possible to make an installer that can guess all of these correctly and create the registry key?

Another option would be to install the manifest and executable into a known folder, say under Program Files. However, this means that the host executable can't be updated just by updating the extension. In addition to updating the extension, users would also have to run the separate installer every time to overwrite the old executable with the new one. This doesn't seem very handy either.

Is there something I've missed?

Thanks in advance,
Aki Kanerva

Mihai Coman

unread,
Jan 23, 2014, 9:56:41 AM1/23/14
to chromium-...@chromium.org
Hi Aki,

There are two places where paths are used:
1. inside the native messaging host json config file; in this case, on Windows ONLY, you can use relative paths (relative to the location of the manifest)
2. in Windows registry when setting the path to the native messaging host manifest; you have to use full paths in this case

While I agree that it would be very "cool" to be able to bundle the native messaging host with your extension, I don't see how you could reliably do that with the current setup: even if you could do it on Windows, in Linux & OSX, the manifest has to be placed in a certain folder and not in the same folder the extension is deployed to.

It could be possible to use a relative path to extension inside the manifest itself - something like "%extension%\app.exe"; extensions, however, are and should remain OS agnostic. 

Bottom line, I think that you should take the 2nd option: leave your extension OS agnostic and place your native messaging host in a separate, OS specific, installer.

OR give up on native messaging hosts, switch to NaCl and have it bundled with your extension.

Mihai

Guerry Semones

unread,
Jan 23, 2014, 11:58:45 AM1/23/14
to chromium-...@chromium.org
Hi Aki,

What you are proposing has been posted as a bug/feature/whatever request at the link below. There is some discussion there, and last I saw, this was being considered. Our team would also like to see a solution like this.


Thanks,

G

Aki Kanerva

unread,
Jan 24, 2014, 6:35:18 AM1/24/14
to chromium-...@chromium.org
Hi Guerry,

That looks like exactly what we need as well.

We're trying to utilize new input hardware. NaCl is not an option because its whole point is to prevent OS-level calls, so it's not possible to link hardware driver libraries into a NaCl executable. Native messaging appears to be the only method available at the moment. Since the hardware is only supported on Windows anyway, being OS agnostic isn't an issue.

Looks like a similar discussion is going on in another place, too:

That thread also mentions that bundling the native messaging host would be a good idea, because it would allow the Chrome Web Store to scan for malware. It makes sense - a separate installer for the native messaging host would be outside of Web Store control.

Hope bundling does make it in.

-- Aki

Vidya Pawar

unread,
Feb 12, 2014, 6:10:27 PM2/12/14
to chromium-...@chromium.org
Hi Aki,

After reading through this thread, looks like you might have the answer to my issue

I am trying to do the similar stuff like accessing the hardware diagnostics information,which uses system files and calls, so NACL is not an option.

I am trying to do it on Linux. Basically I do have the Linux utility which displays hardware diagnostics information, so I want to utilize that command line (I believe that could be my native host ,please correct me I am wrong)

I just gone through the following link


and trying to run the sample native messaging application given in link below on Linux


I see the app under app section.

It loads the main.html but after loading the app I am getting  following JavaScript error in the 'Console' section

Uncaught SyntaxError: Invald regular expression: missing /

the com.google.chrome.example.echo.json is copied to appropriate location under my Linux system as below

/etc.opt/chrome/native-messaging-hosts 

After searching about this , I got couple of solutions but still not able to fix this issue.

You have any idea what me causing the issue?

If you have any working example of NativeMessaing host,that would really help me to expatiate my experiment.

Kindly reply.

Thank you in advance!

Thanks and Regards,
-Vidya 

Aki Kanerva

unread,
Feb 17, 2014, 4:38:09 AM2/17/14
to chromium-...@chromium.org
Hi Vidya,

That looks more like a regular javascript error that doesn't have anything to do with native messaging. You would get that error if your code contains text that isn't properly enclosed in quotes and also has a slash in it. In javascript, enclosing a string in slashes instead of quotes makes it a regular expression, which is used for some things like string.match() and string.replace().

For example:
  var s = /foo/bar;
should be:
  var s = "/foo/bar";

This is just a wild guess, but are you perhaps trying to launch your native host using the executable path instead of the name? The argument you need to pass to chrome.runtime.connectNative() is the name defined in the manifest, not the actual executable path. For example, if your host manifest looks like this:

{
  "name": "com.mynamespace.myhost",
  "description": "Example native messaging host",
  "path": "host.sh",
  "type": "stdio",
  "allowed_origins": [
    "chrome-extension://my-extension-id/"
  ]
}

Then you would launch it in your extension code like this:

  var host = "com.mynamespace.myhost";
  var port = chrome.runtime.connect(host);



-- Aki

Vidya Pawar

unread,
Feb 18, 2014, 2:01:53 PM2/18/14
to Aki Kanerva, chromium-...@chromium.org
Hi Aki,

Thank you!.
That error has been gone.  Now when I am trying to send a message to Native app it gives to following error

Failed To connect : error when communicating with the native messaging host"

The Port Objects OnDisconnect() get called during the SendMessage() call.

In my case as I am using Native Messaging API, I am using

var host = "com.google.chrome.example.echo";
var port = chrome.runtime.connectNative(host);

As I said earlier I am trying to do the similar stuff like accessing the hardware diagnostics information,which uses system files and calls, so using Native Messaging APIs

I am getting same error on Linux and Windows.

Do you have any working example of this.

Thank you!

Thanks and Regards,
-Vidya






--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/51ad1612-158c-44f6-90ae-181185183d18%40chromium.org.



--
-Vidya

Rajesh Katalkar

unread,
Feb 18, 2014, 2:13:11 PM2/18/14
to Vidya Pawar, Aki Kanerva, chromium-...@chromium.org

The example needs python. ..have you installed it....check what are it's dependency and install it.....

I have used a very old example but it may be changed and improved now.  

Sent from LG

Vidya Pawar

unread,
Feb 19, 2014, 12:41:13 PM2/19/14
to Rajesh Katalkar, Aki Kanerva, chromium-...@chromium.org
No, I have used the install.sh .
and the .json got copied to appropriate path which is /etc/opt/chrome/native-messaging-hosts

the "path" is also pointing to the correct value

"path": /home/vidya/Bay/BYT-Chrome-App/host/NativeMsg-Example/host/native-messaging-example-host

in the above value it should be native-messaging-example-host.py  OR native-messaging-example-host

the folder structure is same as given in the 


like 

-app
   - icon-128.png
   -main.html
   -main.js
   -manifest.json

-host
 -com.google.chrome.example.json
 -install_host.sh
 -native-messaging-example-host.py
 -uninstall_host.sh

does this look appropriate?

Thanks and Regards,
-Vidya



On Tue, Feb 18, 2014 at 8:13 PM, Rajesh Katalkar <rajesh...@gmail.com> wrote:

By error it looks like it has not found the native host.I don't know about linux environment as I use windows. ...
   Did you place the json file in proper place. ...are you doing this manually?
     If you have not already done it,  I will suggest using install.sh script provided with the example  to install the host properly

Sent from LG

On Feb 19, 2014 6:52 AM, "Vidya Pawar" <vidyap...@gmail.com> wrote:
When I step into the port.postMessage() function it gives me error
Uncaught Error: Attempting to use a disconnected port object"

When I run the native-messaging-host-example.py , it pop-ups the window it mean there is no issue with the Native application.

While communicating I am getting the above error.

You have any idea?

Thanks and Regards,
-Vidya


On Tue, Feb 18, 2014 at 12:54 PM, Vidya Pawar <vidyap...@gmail.com> wrote:
Hi Rajesh,

yes I have installed Python 2.7.6 on Windows and my Linux system has Python 2.7.3

The documentation did not mention any other dependencies.

Thanks and Regards,
-Vidya
--
-Vidya




--
-Vidya




--
-Vidya

Rajesh Katalkar

unread,
Feb 19, 2014, 1:06:16 PM2/19/14
to Vidya Pawar, Aki Kanerva, chromium-...@chromium.org

Can you run the same file without extension. ...how do you run that file? Paste the command here. ..

If you see the Windows version. ...bat file...here it runs the file with python comand. ...but that's Windows requirement...
You can try same thing. ..i. e write a shell script file which will run the Python file.and then use this file in path in json.

If this does not help then chrome devs or the author of that example can help you.

Sent from LG

Vidya Pawar

unread,
Feb 19, 2014, 1:19:15 PM2/19/14
to Rajesh Katalkar, Aki Kanerva, chromium-...@chromium.org
Yes, I tried it and I am able to run the alone python native app.

from the command line I give the following command  and a Window having name as 'Native-Messaging-Example' comes properly.

python ./native-messaging-example-host.py

the problem is in making the connection.
As per the documentation my understanding was, the app will look for .json in /etc/opt/chrome/native-messaging-hosts from where it will get the PATH for the native application in this case  is as below

/home/vidya/Bay/BYT-Chrome-App/host/NativeMsg-Example/host/native-messaging-example-host

then the communication will happen,

No issues with just running the .py file. 

How can I do the message passing?

--
-Vidya

Vidya Pawar

unread,
Feb 19, 2014, 1:48:09 PM2/19/14
to Rajesh Katalkar, Aki Kanerva, chromium-...@chromium.org
when I click on connect it display following message 

Failed to connect : Naive host has exited

any idea?

--
-Vidya

Vidya Pawar

unread,
Feb 19, 2014, 2:54:50 PM2/19/14
to Rajesh Katalkar, Aki Kanerva, chromium-...@chromium.org
I put the breakpoints in python file and debug the python file with pdb.

from the packaged app  when I click on connect , the control does not even come to the breakpoint set in the python file.

It means it is not even starting / making the connection with the native application.

reply if anyone face these problems ?

--
-Vidya

Vidya Pawar

unread,
Feb 19, 2014, 5:05:56 PM2/19/14
to Rajesh Katalkar, Aki Kanerva, chromium-...@chromium.org
Finally I am able to make it run without any issues 

when I replace the ' Path' value from .json file 
from
/home/vidya/Bay/BYT-Chrome-App/host/NativeMsg-Example/host/native-messaging-example-host

to 
/home/vidya/Bay/BYT-Chrome-App/host/NativeMsg-Example/host/native-messaging-example-host.py

It started running. :)

so there is a bug in install_host.sh 
on Linux the Path value should be  "native-messaging-example-host.py"

Cheers!
-Vidya



--
-Vidya

Rajesh Katalkar

unread,
Feb 20, 2014, 10:59:48 AM2/20/14
to Vidya Pawar, Aki Kanerva, chromium-...@chromium.org

That's great Vidya ,that you solved the problem . No idea how others did not face this problem. You should report this to the author. ...

Sent from LG

Vidya Pawar

unread,
Feb 20, 2014, 4:10:28 PM2/20/14
to Rajesh Katalkar, Aki Kanerva, chromium-...@chromium.org
Now does anyone has any working example of Native host written in C++?


--
-Vidya

Rajesh Katalkar

unread,
Feb 21, 2014, 12:44:03 PM2/21/14
to Vidya Pawar, Aki Kanerva, chromium-...@chromium.org

Vidya, take look at this discussion which I had when I developed native host for windows. .you can use the same. ..it just has basic code of reading and writing. ...I did not completely update the code in post. ...but you can use the same style to write as was used to read....i. e use cout.write etc....also you have to use some jsonlibrary to parse etc.

https://groups.google.com/a/chromium.org/forum/?nomobile=true#!mydiscussions/chromium-apps/i8K1vIJXB2w

Sent from LG

Vidya Pawar

unread,
Mar 7, 2014, 6:19:36 PM3/7/14
to chromium-...@chromium.org, Vidya Pawar, Aki Kanerva, chromium-...@chromium.org
Hi,

Here is the code which I am using as  a Native-host in C++ got from the link below


while testing I got the issue that the code below is not sending more than 250 bytes ?Anybody know what might be causing the issue 

int main(int argc, char* argv[])
{
    std::cout.setf( std::ios_base::unitbuf ); //instead of "<< eof" and "flushall"
    unsigned int a, c, i, t=0;
    std::string inp;  
    bool bCommunicationEnds = false;
    
    do {

        inp="";
        t=0;
        // Sum the first 4 chars from stdin (the length of the message passed).
        for (i = 0; i <= 3; i++) 
        {
//          t += getchar();
            t += std::cin.get(); 
        }
        // Loop getchar to pull in the message until we reach the total
        //  length provided.
        for (i=0; i < t; i++) 
        {
            //c = getchar();
            c = std::cin.get(); 
            //if(c == EOF)
            if(c == 65)
            {
                bCommunicationEnds = true;
                i = t;
            }
            else
            {
                inp += c;
            }
        }

        if(!bCommunicationEnds)
        {
            //Collect the length of the message
             unsigned int len = inp.length();
            //unsigned int len = strJson.length();
            //// We need to send the 4 btyes of length information
            std::cout << char(((len>>0) & 0xFF))
                << char(((len>>8) & 0xFF))
                << char(((len>>16) & 0xFF))
                << char(((len>>24) & 0xFF));
            //// Now we can output our message
            std::cout << inp;
            
        }
    }while(!bCommunicationEnds);
    return 0;
}




Thanks and Regards,
-Vidya
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsub...@chromium.org.

To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.



--
-Vidya

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsub...@chromium.org.

To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.



--
-Vidya




--
-Vidya




--
-Vidya




--
-Vidya




--
-Vidya




--
-Vidya




--
-Vidya




--
-Vidya

Mihai Coman

unread,
Mar 10, 2014, 6:09:42 AM3/10/14
to chromium-...@chromium.org, Vidya Pawar, Aki Kanerva
That code is wrong:
        for (i = 0; i <= 3; i++) 
        {
//          t += getchar();
            t += std::cin.get(); 
        }

Even in decimal, if I send 1024 as 4 chars (1,0,2,4), all that code does is add them together and instead of getting a length of 1024, you'll get a "slightly" different value of X = 1+0+2+4.

Try this instead (should work, unless you're targeting some IBM mainframes and such; ARM can be fun too - I didn't test it):
uint32_t len = 0;
std::cin.read((char*)&len,sizeof(len));

Rajesh Katalkar

unread,
Mar 10, 2014, 6:29:47 AM3/10/14
to Mihai Coman, Chromium-extensions, Vidya Pawar, Aki Kanerva
Vidya,
         Mihai is right.
Check my thread ..I think I already suggested this to you.The correct way is to use reinterpret_case<> ...
read code in my last comment.
https://groups.google.com/a/chromium.org/forum/#!mydiscussions/chromium-apps/i8K1vIJXB2w


   int uint32_t = 0;
   cin.read(reinterpret_cast<char*>(&cnt) ,4);

   for writing back response string
   cnt = length of response string
   cout.write(reinterpret_cast<char*>(&cnt),4);
   cout<<data<<flush;



To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.

To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.

Rajesh Katalkar

unread,
Mar 10, 2014, 6:31:25 AM3/10/14
to Mihai Coman, Chromium-extensions, Vidya Pawar, Aki Kanerva
typo in code for writing

   for writing back response string
   cnt = length of response string
   cout.write(reinterpret_cast<char*>(&cnt),4);
   cout<<response<<flush;

Vidya Pawar

unread,
Mar 13, 2014, 9:23:10 PM3/13/14
to Rajesh Katalkar, Mihai Coman, Chromium-extensions, Aki Kanerva
Hi , 
Thank you for the solution. It is working fine now.

I am trying to run the native messaging app from "Chromium" OS ,

I am getting Native messaging host not found error.

Do I need to manually create /etc/opt and copy the Manifest file for host?

I have also tried on On chromebook pixel booted in developer mode but it is not allowing me to create the /etc/opt 

How to manually deploy and test native host messaging app on a chrome book and Chromium in developer mode?

Thanks and Regards,
-Vidya
--
-Vidya

Mohammed Altaf

unread,
Aug 10, 2016, 5:34:54 AM8/10/16
to Chromium-Extensions-Announce, rajesh...@gmail.com, mi...@quickweb.ro, aki....@gmail.com
Does anyone have a solution for Linux NativeMessaging with chrome
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsubscribe...@chromium.org.

To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.



--
-Vidya

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsubscribe...@chromium.org.

To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.



--
-Vidya




--
-Vidya




--
-Vidya




--
-Vidya




--
-Vidya




--
-Vidya




--
-Vidya




--
-Vidya

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsub...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.





--
-Vidya

Reply all
Reply to author
Forward
0 new messages