About Native Messaging Host

1,904 views
Skip to first unread message

Yan Jun

unread,
Nov 19, 2013, 12:50:58 AM11/19/13
to chromium-...@chromium.org
Hi everyone, I am using native messaging API, and I want to ship the native application within my extension. 

In Windows, I add a registry key under HKLM\SOFTWARE\Google\Chrome\NativeMessagingHosts. Since my application is inside the extension folder after installed, I reference the full path by "%LOCALAPPDATA%\Google\Chrome\User Data\Default\Extensions\***\***.json". But in this way, my extension complains "Specified native messaging host not found.".

If I expand the %LOCALAPPDATA% and write the path as "C:\Users\***\AppData\Local\Google\Chrome\User Data\Default\Extensions\***\***.json", then my extension can successfully communicate with the host.

I wonder if this is an intended behavior? Thank you for your help.

Jeffrey Yasskin

unread,
Nov 19, 2013, 2:23:23 PM11/19/13
to Yan Jun, asargent, Chromium-extensions
I believe that's expected. We'd have to explicitly expand environment
variables in the registry key in order to make %LOCALAPPDATA% work,
and that would make the selected program depend on how the user ran
Chrome. http://developer.chrome.com/extensions/messaging.html#native-messaging-host
says "set default value of that key to the full path to the manifest
file." but doesn't explicitly say that environment variables aren't
considered.
> --
> 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/750d98de-c76a-4d02-a475-3abeffafea03%40chromium.org.
> For more options, visit
> https://groups.google.com/a/chromium.org/groups/opt_out.

Jamie Walch

unread,
Nov 19, 2013, 5:10:07 PM11/19/13
to Jeffrey Yasskin, Sergey Ulanov, Yan Jun, asargent, Chromium-extensions
I don't think that this is the intended location for native messaging hosts. In particular, it relies a specific location for Chrome's profile data. You should instead have an installer for your native component and have that create the registry key with the appropriate manifest location.


Antony Sargent

unread,
Nov 19, 2013, 5:30:08 PM11/19/13
to Jamie Walch, Jeffrey Yasskin, Sergey Ulanov, Yan Jun, Chromium-extensions
I suppose we could add explicit support for this with some kind of special token like __EXTENSION_INSTALL_DIR__ that gets expanded to the right value inside chrome. Then developers would not have to roll their own autoupdate solution for the native binary. We'd certainly have to give some careful thought to whether there would be any potential security problems with this. 

Antony Sargent

unread,
Nov 19, 2013, 5:42:59 PM11/19/13
to Jamie Walch, Jeffrey Yasskin, Sergey Ulanov, Yan Jun, Chromium-extensions
Sorry, I guess part of the problem is that the version number changes on updates, so we'd need to have the replacement string be more like:

__odmpalfplhaahlgnkkonchfhpegdcgjm_CURRENT_VERSION_DIR__

where id is one particular extension id. Then this value would get mapped to, e.g.

<path to Profile>/Extensions/odmpalfplhaahlgnkkonchfhpegdcgjm/0.7.3_0/ 






Yan Jun

unread,
Nov 19, 2013, 10:30:40 PM11/19/13
to chromium-...@chromium.org, Jamie Walch, Jeffrey Yasskin, Sergey Ulanov, Yan Jun
Thank you all!
I agree with Antony's suggestion. My current method is really a big hack, and I also need to handle the version number. If the version number changes, the users will be asked to configure the registry key again. Adding this support will surely ease the installation and update for native messaging host.

在 2013年11月20日星期三UTC+8上午6时42分59秒,Antony Sargent写道:

> 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/750d98de-c76a-4d02-a475-3abeffafea03%40chromium.org.
> For more options, visit
> https://groups.google.com/a/chromium.org/groups/opt_out.

--
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/.
Message has been deleted

Sergey Ulanov

unread,
Nov 19, 2013, 11:59:44 PM11/19/13
to chromium-...@chromium.org
Hi Yan,
How do you install the native messaging host binary? You should bundle native messaging host manifest file with the native messaging host binary itself (and on Windows you would normally want to place it in the same directory). The manifest shouldn't be part of your webapp. If you bundle the manifest file together with the host then you wouldn't need to know the path where chrome unpacks the extension.
Message has been deleted

Yan Jun

unread,
Nov 20, 2013, 12:25:10 AM11/20/13
to chromium-...@chromium.org
Hi Sergey,

I am replacing the NPAPI in my extension with native messaging host. I want to put my binary and manifest file within the same directory as the extension, and guide the users to add a registry key that points to the directory. In this way, my binary can be updated together with the extension.

I am not sure if this is a good idea or actually allowed.

Thanks!

Jeffrey Yasskin

unread,
Nov 20, 2013, 12:31:43 AM11/20/13
to Yan Jun, Chromium-extensions
FWIW:
* I'm pretty sure this possibility wasn't considered when native
messaging was designed
* There's a risk that it would be easier to trick a user into
installing an extension and modifying a registry key than it would be
to trick them into downloading and running a malicious app. However, I
think that risk is low.
* Having the native messaging host inside the .crx has similar
security benefits as having the .crx in the web store.

So, overall, I think this would be a reasonable feature to support
(although my opinion isn't the decisive one). Please file a feature
request at http://crbug.com/new so the right people can look at it.
> --
> 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/7a58a845-8f18-4cf6-96b9-f9f430f87563%40chromium.org.

Yan Jun

unread,
Nov 20, 2013, 12:38:29 AM11/20/13
to chromium-...@chromium.org
Thank you! I will file a feature request then.
Message has been deleted

Yan Jun

unread,
Nov 20, 2013, 10:18:50 AM11/20/13
to chromium-...@chromium.org
Reply all
Reply to author
Forward
0 new messages