Thordax
Thordax

Reputation: 1733

Chrome native messaging cannot execute batch file

Here is the manifest of my host :

{
   "allowed_origins" : 
    [ 
        "chrome-extension://EXTENSION_ID/"
    ],
   "description" : "my.app.host",
   "name" : "my.app.host",
   "path" : "‪C:\\chromejar\\launch.bat",
   "type" : "stdio"
}

Here is the content of my launch.bat file :

setlocal enableextensions disabledelayedexpansion

for %%a in ("%~dp0\ChromeConnector.jar") do set "JARFILE=%%~fa"
    java -jar "%JARFILE%"
pause

Is there another way to test the jar application ?

Thanks in advance

Upvotes: 0

Views: 1115

Answers (1)

H Lopez
H Lopez

Reputation: 36

Here are some answers to your questions:

1. Can I test only the BAT part of it ? (put an echo text from the BAT to see the result on my app ?)

In your BAT, you can send the output of your Java program to a text file. If the file exists after trying the call, it means the extension was able to launch the native app and you will be able to see the app output. For example, in the fourth line of your BAT you can do this:

java -jar "%JARFILE%" >> mybatfile.log

2. I tried to enable logging in chrome using this line : start chrome --enable-logging --v=1 but no particular log seems to be found in AppData\Local\Google\Chrome\User Data\chrome_debug.log, Do I need to add something to log particular errors ?

Look for messages including "native_message_process_host.cc", for example:

[4680:5612:0809/194917:ERROR:native_message_process_host.cc(291)] Native Messaging host tried sending a message that is 2036688930 bytes long.

3. My Java code is as simple as this for the moment :

public static void main(String[] args) {
    while(true) { }
}

Refer to this post for receiving and sending stdio messages from java: Java native messaging with chrome extension - cannot correctly write length

4. Is there another way to test the jar application ?

I suggest to generate logs from your java app, so you can review the received and sent messages, including the initial 4 bytes denoting the messages length.

Upvotes: 1

Related Questions