Receiving native messages from Chrome in Java

大兔子大兔子 提交于 2019-12-11 10:57:26

问题


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:


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.



来源:https://stackoverflow.com/questions/23500361/receiving-native-messages-from-chrome-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!