0

I downloaded the official Chrome nativeMessaging example to test it out.

To do this, I installed the app from chrome://extensions, by choosing Load Unpacked. No problems so far.

I then installed the host. I'm using Windows 7, so I ran install_host.bat, which claimed that "The operation completed successfully." However, when I go to chrome://apps/ and click the Connect button, I get this error:

Failed to connect: Native host has exited.

Is there some reason this would happen? Restarting Chrome did not fix the issue, nor did uninstalling and then reinstalling the host program.

(I noticed that native-messaging-example-host.bat requires Python 2, so I modified it to run Python 2 explicitly. If I run native-messaging-example-host.bat from the command line, it pops up a little example program of its own with a GUI and seems to work correctly.)

Pat Flegit
  • 183
  • 1
  • 2
  • 11
  • I can confirm that the following registry entry was created: HKEY_CURRENT_USER\Software\Google\Chrome\NativeMessagingHosts\com.google.chrome.example.echo. Its value points to the ...\host\com.google.chrome.example.echo-win.json file from the downloaded example. – Pat Flegit Mar 04 '19 at 03:04
  • Make sure `python.exe` is in PATH or edit native-messaging-example-host.bat to point to the correct executable. For example I've used `py -2` instead. – wOxxOm Mar 04 '19 at 04:42
  • It is in the path. I also tried using an absolute path directly to the Python 2 executable. – Pat Flegit Mar 04 '19 at 05:07
  • Since it works for me, the example is probably correct. Try looking for answers/articles on how to debug nativeMessaging like --enable-logging and so on. – wOxxOm Mar 04 '19 at 05:18
  • You don't need to run the host manually in the background, right? When you click Connect, the app should start the host automatically, right? – Pat Flegit Mar 04 '19 at 06:28
  • Yes, it should start automatically. Another debugging idea: add `msg %SESSIONNAME% foo` to the batch file so you know it starts at least. – wOxxOm Mar 04 '19 at 06:33

1 Answers1

0

Turns out I was using a non-standard character in the path leading to the host executable. This wouldn't be a problem for any other program, but Chrome's native messaging API doesn't like it, I guess.

By the way, the documentation on setting up this example is near-nonexistent, but this stack overflow link has some useful info: Chrome Extension NativeMessaging 'connectNative' undefined

Pat Flegit
  • 183
  • 1
  • 2
  • 11