问题
I have written a chrome app and a native messaging host in Java. The combo works fine on linux. However when I try to port the combo to windows the communication can not be established. The jar where the host is contained is exactly the same as the linux variant. I am using the following script (start.bat) to start the Java host:
@echo off
java -jar "%~dp0theHost.jar"
The json manifest is as follows:
{
"name": "com.service.host",
"description": "Native messaging host",
"path": "start.bat",
"type": "stdio",
"allowed_origins": [
"chrome-extension://--the ID--/"
]
}
I have configured the HKEY_LOCAL_MACHINE\SOFTWARE\Google\Chrome\NativeMessagingHosts\com.service.host to the path e:\hosts\com.service.host.json
the service.bat file together with the jar (theHost.jar) is also in the e:\hosts\ directory.
When trying to start the communication I get the error: Error when communicating with the native messaging host.
I also tried to change the path in the manifest to: e:\\hosts\\start.bat
but the result/error is the same.
When I start the bat file manually in the cmd window the host initializes properly as far as I can tell and waits for the message from the Chrome app. Also, when I added the line:
copy NUL empty.txt
before the "java - jar..." line to create an empty file when the bat is invoked, the empty file is created when the bat is started manually and is not created when "invoked" by the chrome app. Any help would be greatly appreciated.
Versions: Windows 7, Java 7u55, Chrome 34.0.1847.116 m
回答1:
To debug errors that do not give meaningful messages in JS context, you can try using Chrome logging; this can give more information (which helped in your case).
回答2:
The name of host is to long. Delete current host from registry and recreate it with shorter name. E.g.:REG ADD "HKCU\Software\Google\Chrome\NativeMessagingHosts\com.chrome.example" /ve /t REG_SZ /d "%~dp0com.google.chrome.example.echo-win.json" /f
来源:https://stackoverflow.com/questions/23105921/chrome-app-fails-to-communicate-with-native-host-on-windows