Receiving native messages from Chrome in Java

2019-08-11 10:09发布

I am trying to get native messaging between a chrome extension and a Java program to work. After some struggling I now can open my Java program with:

var port = chrome.extension.connectNative('fbehost');
port.postMessage({ text: "Hello, my_application" });

But I don't know how I can read the message send from my extension. I created a program which opens a simple JFrame with a textarea. As it says in the documentation that native messaging communicates with stdin and stdout, I tried to get the message with:

while(true) {
  try {
    input=br.readLine();
    tf.setAreaText(input);
  } catch(Exception e) {
  }
}

Also tried it with:

System.in.read()

The jar gets executed but the textarea stays empty. I can't find any information on the internet how to get the data in Java. Can you help me?

1条回答
够拽才男人
2楼-- · 2019-08-11 10:32

I haven't been able to get any native messaging to work in Google Chrome recently. I remember reading somewhere that a semi-recent update appeared to prevent compatibility between Java and Chrome for native messaging. Best of luck.

查看更多
登录 后发表回答