Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从扩展与本机消息传递主机通信时出错_Javascript_Google Chrome_Google Chrome Extension - Fatal编程技术网

Javascript 从扩展与本机消息传递主机通信时出错

Javascript 从扩展与本机消息传递主机通信时出错,javascript,google-chrome,google-chrome-extension,Javascript,Google Chrome,Google Chrome Extension,我需要把网页上的电话号码传给桌面拨号器。我有一个主机,它从background.js传递的页面捕获电话号码: var responseMessage = ""; chrome.runtime.onMessage.addListener( function(request, sender, sendResponse) { console.log(request.phonenumber); chrome.runtime.sendNativeMessag

我需要把网页上的电话号码传给桌面拨号器。我有一个主机,它从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);
  });
并将其发送到主机:

{
  "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 %*
一般来说,暂时没有主机,会有一个应用程序从JSON打开一个对象并将其发送到拨号程序。然而 我编写了一个简单的记录器,这是一个输出:

1argument: chrome-extension://lbhgehbjeemkjmooaeopmfljahdoombd/
2argument: --parent-window=0
当我尝试发送号码时,我进入了控制台 “与本机消息传递主机通信时出错。”以及如何查看没有传递给主机侦听器的号码。
有人能建议我找个地方修理一下吗

好的。还有一个问题。我尝试读取传入的消息,但得到零大小的稳定性

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;
    }

在这种情况下我错过了什么?

我解决了这个问题。问题在于启动器中缺少
@echo off

该消息不是作为参数发送的,请参阅:您的本机主机应使用标准stdin/stdout流。看看它是如何在文档中链接的演示中实现的谢谢你的帮助,我没有仔细阅读文档。
{text: 4325345423}