Alexander  Verzakov
Alexander Verzakov

Reputation: 39

Error when communicating with the native messaging host from extension

I need to pass phonenumber from web page to desktop dialer. I have host, that catches phone number from page that passed from background.js:

var responseMessage = "";
chrome.runtime.onMessage.addListener(
  function(request, sender, sendResponse) {
      console.log(request.phonenumber);
                chrome.runtime.sendNativeMessage('com.avvd.microsipcallfield', {text: request.phonenumber},function(response) {
    if (chrome.runtime.lastError) {
        responseMessage = chrome.runtime.lastError.message
        console.log(responseMessage);
    } else {
        responseMessage = response;
                }} )
      sendResponse(responseMessage);
  });

and sending it to host:

{
  "name": "com.avvd.microsipcallfield",
  "description": "Call Field Microsip host",
  "path": "C:\\Users\\All Users\\callFieldHost\\host.bat",
  "type": "stdio",
  "allowed_origins": [
    "chrome-extension://lbhgehbjeemkjmooaeopmfljahdoombd/"
  ]
}

Host.bat

java -jar HostDecoder.jar %*

in general, for the time being there is no host, there will be an application that opens an object from JSON and sends it to the dialer. However I wrote simple recorder and this is an output:

1argument: chrome-extension://lbhgehbjeemkjmooaeopmfljahdoombd/
2argument: --parent-window=0

While i try to send number i get in console "Error when communicating with the native messaging host." and how we can see there is no number passed to host listener. Can somebody advice me to look for to repair this?

Upvotes: 0

Views: 4783

Answers (2)

Alexander  Verzakov
Alexander Verzakov

Reputation: 39

I resolve issue. Trouble was in absent @echo off in launcher.

Upvotes: 3

Alexander  Verzakov
Alexander Verzakov

Reputation: 39

Ok. There is another question. I try to read incoming messages but get stability zero size.

private String read(InputStream in) throws IOException {
        byte[] length = new byte[4];
        in.read(length);
        int size = getInt(length);
        if (size == 0) {
            throw new InterruptedIOException("Zero size message");
        }

        byte[] message = new byte[size];
        in.read(b);

        return new String(message, "UTF-8");
    }

    private int getInt(byte[] bytes) {
        return  (bytes[3]<<24) & 0xff000000|
                (bytes[2]<<16) & 0x00ff0000|
                (bytes[1]<< 8) & 0x0000ff00|
                (bytes[0]<< 0) & 0x000000ff;
    }


I send with native message an object

{text: 4325345423} 

What i miss in this case?

Upvotes: 0

Related Questions