How to exchange messages with native applications

551 views
Skip to first unread message

Daniel R. Baleato

unread,
Mar 2, 2017, 9:57:03 AM3/2/17
to nw.js
Hi all,

I'm using NW.js to package a webapp that plays video content. Our webapp needs to communicate to a native application to handle DRM and streaming. The app is working in Chrome and Chromium via Native Messaging but using NW.js I couldn't get it working. It logs the following error:

[86985:53507:0302/151439.883227:ERROR:native_process_launcher.cc(130)] Can't find manifest for native messaging host com.company.application

Due the call:

chrome.runtime.connectNative("com.company.application");


My take on this is that I have to specify where the NativeMessagingHosts path is (where the native messaging host configuration manifest "com.company.application.json" is). Is this correct? How can I specify that?

I also wonder if I'd be able to include this native application inside the nw.js app and avoid a second install by the user.

Thanks in advance for your feedback.

Kind regards,
Daniel

Roger

unread,
Mar 2, 2017, 10:06:27 AM3/2/17
to Daniel R. Baleato, nw.js
It should be specified following the API documentation which you referred to: https://developer.chrome.com/extensions/nativeMessaging#native-messaging-host-location

--
You received this message because you are subscribed to the Google Groups "nw.js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nwjs-general...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Daniel R. Baleato

unread,
Mar 2, 2017, 10:13:32 AM3/2/17
to nw.js, bal...@gmail.com
Thanks for your fast reply Roger.

Yes, I'm using Mac so I have the manifest for Chromium in:  ~/Library/Application\ Support/Chromium/NativeMessagingHosts/com.company.application.json and for Chrome in: ~/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/com.company.application.json. Works in both of them but fails with NW.js

Daniel R. Baleato

unread,
Mar 2, 2017, 10:22:51 AM3/2/17
to nw.js, bal...@gmail.com
Just to clarify, our webapp uses an extension (by our player provider) that is the one that requires connection to the native app I mention. I'm loading that extension also with NW.js but when the extension loads and calls chrome.runtime.connectNative fails with: 

[86985:53507:0302/151439.883227:ERROR:native_process_launcher.cc(130)] Can't find manifest for native messaging host com.company.application

Thanks

Daniel R. Baleato

unread,
Mar 2, 2017, 1:04:51 PM3/2/17
to nw.js, bal...@gmail.com
Ok, I got it working by passing --user-data-dir=user-data-dir and copying the native messaging host configuration manifest to user-data-dir/NativeMessagingHosts/com.company.application.json inside the NW.js app folder.

Myer Nore

unread,
Jun 6, 2017, 10:59:51 AM6/6/17
to nw.js, bal...@gmail.com
@Daniel, did you ever try this on Windows? If so, did you use registry updates to do it, or the method described here?

Daniel R. Baleato

unread,
Jun 6, 2017, 11:09:27 AM6/6/17
to Myer Nore, nw.js
Hi @Myer, on Windows I'm using the registry to locate the binary. The method described here is used for Mac only.
I'd like to avoid updating the registry, so if you find other approach to that I'd appreciate that you let me know! Cheers.

Myer Nore

unread,
Jun 7, 2017, 3:17:04 PM6/7/17
to nw.js, myer...@gmail.com
I will update you if I find another method. Right now it looks like the only way that I've found. By chance, do you remember if you used Chrome's NativeMessagingHost space in the Windows registry or if you used one for nw.js, or whether it was app-specific? There doesn't seem to be much documentation on if or how nw.js's Chromium looks for registry keys to configure Native Messaging.

xbin....@gmail.com

unread,
Aug 4, 2017, 11:52:46 PM8/4/17
to nw.js, myer...@gmail.com
Hi @Myer, did you make it work on windows? I have tried using registry or making NativeMessagingHost inside user-data-dir,  neither of them works. I didn't get the message of "Can't find manifest for native messaging host...", it just disconnect after calling
 
chrome.runtime.connectNative('com.my_company.my_application')

The same code works fine in chrome extension or app.

I also tried sending message without creating a port:

chrome.runtime.sendNativeMessage('com.my_company.my_application',
 
{ text: "Hello" },
 
function(response) {
    console
.log("Received " + response);
 
});

I got the "Received undefined" in the console.

Is there something I've missed?

If you ever make it work on windows, please let me know.  Thanks in advance.

Myer Nore

unread,
Aug 5, 2017, 5:27:27 AM8/5/17
to xbin....@gmail.com, nw.js
Hi Xbin Cheng, 
I did get it to work on both Windows and Mac. The key was that on Windows, one needs to edit the registry value `HKEY_CURRENT_USER\SOFTWARE\Google\Chrome\NativeMessagingHosts\com.my_company.my_application`. The value needs to point to the json file describing the handler of the messages: `C:\Program Files\Your Company\Your Program\\com.company.program.jsdk.json`
Myer

xbin....@gmail.com

unread,
Aug 6, 2017, 4:08:22 AM8/6/17
to nw.js, xbin....@gmail.com
@Myer, thanks for the quick response! It works for me now. 

I found it didn't work with the nwjs built by myself. After I changed to official nwjs, it works as expected. I must have missed some parameters when building nwjs.

Thanks for your help. 
Reply all
Reply to author
Forward
0 new messages