1

I'm developing a google-chrome application and I need to launch a Java application. (Really, I need to read and save files without a choosefile pop-up).

As NPAPI library has been deprecated, I have looked for alternatives and I have decided to use "Native messaging hosts" to launch the external application.

To create my first example, I have tried to launch a shell script because I think that is more easy. However I have not managed to launch the script. I'm developing in linux

The manifest file is in this path

"/etc/opt/chrome/native-messaing-hosts/com.centeropenmiddleware.l3p1.xmleditor.json":

and the contain is:

{
  "name": "com.centeropenmiddleware.l3p1.xmleditor",
  "description": "Saving a file",
  "path": "/home/paco2/pp.sh",
  "type": "stdio",
  "allowed_origins": [
    "chrome-extension://plfnjepfbddljeogeacemcpceiofapnm/"
  ]
}

The application id is plfnjepfbddljeogeacemcpceiofapnm

the script creates a file:

#!/bin/bash
echo hola mundo >> aaa

The application code fails in this line:

try {
    var port = chrome.runtime.connectNative ('com.centeropenmiddleware.l3p1.xmleditor')
} catch (e) {
    console.log(e);
    return;
}

The error caught is

{
    message : "Error connecting to native app: com.centeropenmiddleware.l3p1.xmleditor",
    stack : "Error: Error connecting to native app: com.centeropenmiddleware.l3p1.xmleditor
             at Object.<anonymous> (extensions::runtime:189:11)
             at Function.target.(anonymous function) (extensions::SafeBuiltins:19:14)
             at Object.handleRequest (extensions::binding:55:27)
             at Function.target.(anonymous function) (extensions::SafeBuiltins:19:14)
             at Object.<anonymous> (extensions::binding:318:32)
             at saveas (chrome-extension://plfnjepfbddljeogeacemcpceiofapnm/js/editorRoutines.js:104:35)
             at HTMLButtonElement.sendFileContentFromEditor (chrome-extension://plfnjepfbddljeogeacemcpceiofapnm/js/editorRoutines.js:89:27)"
}

To launch the application I have used these commands

google-chrome --load-and-launch-app=/home/paco2/Projects/UPM/XMLEditor/XMLEditor/ --native-messaging-hosts="com.centeropenmiddleware.l3p1.xmleditor.json=/etc/opt/chrome/native-messaing-hosts/com.centeropenmiddleware.l3p1.xmleditor.json"
google-chrome --load-and-launch-app=/home/paco2/Projects/UPM/XMLEditor/XMLEditor/ 

I use the stablish google chrome version (34.0.1847.132)

Are there any wrong?

fhuertas
  • 4,764
  • 2
  • 17
  • 28

1 Answers1

1

Bash is a bad choice to handle the Chromiums Native Messaging API.

It cannot handle binary info in any efficient way, see this question

I did manage to launch a bash script though. For that I used sendNativeMessage. Sending just once

 chrome.runtime.sendNativeMessage('com.centeropenmiddleware.l3p1.xmleditor',
        {text: "send"},
        function(response) {console.log("Received " + 
                            chrome.runtime.lastError.message);
        });

It will launch /home/paco2/pp.sh, but parsing the message will be difficult in bash, even if it's a short as send.

In short don't use bash for this, try C++, or Python in between and use subprocess.

Community
  • 1
  • 1
Janghou
  • 1,613
  • 1
  • 21
  • 30