0

I am trying to make a page-action extension that will communicate with a native messaging host (that is an EXE file).

I have installed my extension and I see its UI working as expected, but the EXE is not started. Do I need to do something myself to start it apart from that? :

port = chrome.runtime.connectNative(hostName);

I have installed the host in the registry like so:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Google\Chrome\NativeMessagingHosts\com.google.chrome.example.echo] @="C:\Users\me\Desktop\nativeMessaging\host\com.google.chrome.example.echo-win.json"

(I have also added this manually because there seemed to be a mess with the x86 and x64 bit version hives...)

Host Manifest file:

{
  "name": "com.google.chrome.example.echo",
  "description": "Chrome Native Messaging API Example Host",
  "path": "native-messaging-example-host.bat",
  "type": "stdio",
  "allowed_origins": [
    "chrome-extension://knldjmfmopnpolahpmmgbagdohdnhkik/",
    "*"
  ]
}

Inside native-messaging-example-host.bat I have the :

MyExeName.exe

As you can see, I have added a "*" in allowed_origins JUST IN CASE the other option was not right for page actions.

I have also tried to put the EXE name directly inside the manifest file, but again with no luck.

I still get a :

Specified native messaging host not found. 

I also check with ProccessExplorer to see what apps Chrome loads, just in case it gets loaded, but I don't see it there either.

The weird things is that I have started modifying the native messaging host sample from Google and I think it was working as an app. It stopped working when I turned it into a page action extension.

Does anyone have any idea what is wrong here?

user2173353
  • 4,316
  • 4
  • 47
  • 79
  • 1
    You cannot have wildcards in `allowed_origins`. "Specified native messaging host not found." is a generic error. What do you see if you look in stderr of Chrome? See e.g. http://www.chromium.org/for-testers/enable-logging – Rob W Nov 20 '14 at 15:18
  • Thanks! After trying `enable-logging` and going through its logs, I have found two errors (one extra comma in the JSON and the unsupported wild-cards that you've mentioned). Now it seems working! – user2173353 Nov 20 '14 at 15:42
  • Now I get a: `Error when communicating with the native messaging host.` which seems easier to fix - I think. – user2173353 Nov 20 '14 at 15:44
  • Windows batch scripting is not exactly a suitable (scripting) language for native messaging... Try C, C++, C#, Python or any other language, but not windows batch. – Rob W Nov 20 '14 at 15:53
  • Yes, the BAT was only for testing purposes. I have a C++ app now and I am trying to get the response from the host right, following this topic: http://stackoverflow.com/questions/24775096/connectnative-disconnects-by-itself-in-chrome-extension. Thanks for your helpfull answer there too. :) – user2173353 Nov 20 '14 at 16:18
  • I have found some additional helpful info here as well: http://stackoverflow.com/a/22298514/2173353 – user2173353 Nov 20 '14 at 16:21
  • where do you see "Specified native messaging host not found."? – Markus Aug 28 '17 at 20:45
  • @Markus It's been a long time and don't quite remember that, but I guess it should have be on some Chrome console. Most likely on the addon's console (right click on the addon's popup and select inspect element). – user2173353 Aug 29 '17 at 08:27

4 Answers4

2

Aside from turning on logging, you can also take the approach of using procmon from sysinternals. It is like regmon and filemon in one, so you can follow chrome query the registry keys, then read the manifest, then run the executable and you can see where it goes wrong.

I had an issue previously, the exe would not run, and by doing the above, I found there was a small typo in the key, that I had missed.

For enabling logging, look at the following: https://www.chromium.org/for-testers/enable-logging e.g. you can start your browser with following command line arguments: --vmodule=extension_updater=2 --enable-logging

2

I had similar problem: chrome was creating the port, but not starting the program. Tracing with Sysinternals procmon.exe I found that activity stalls with call to C:\Programs\TCCLE\tcc.exe. I use Take Command as cmd.exe replacement and environment variable ComSpec was set to C:\Programs\TCCLE\tcc.exe; I changed ComSpec back to C:\WINDOWS\system32\cmd.exe and the program started.

Roman Mishin
  • 461
  • 5
  • 5
1

I had a similar issue. Enabling logging did not help. Turned out to be in my registry key:

[HKEY_LOCAL_MACHINE\SOFTWARE\Google\Chrome\NativeMessagingHosts

I had quotes around the EXE and path, e.g. "C:\Temp\Chrome\ChromeNativeApp.exe" vs. C:\Temp\Chrome\ChromeNativeApp.exe

1

I had a similar problem. And nothing here helped. What made the problem go away was changing the name of the host from "com.me.DbServer" to "com.me.test". This change made everything suddenly work. I guess that either DbServer is a reserved name or more likely that uppercase letters are not allowed. I am using Chrome 69.

C. Szabo
  • 97
  • 7