Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/27.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
Linux 为什么SendNativeMessage说我尝试发送2G字节的消息?_Linux_Firefox Addon - Fatal编程技术网

Linux 为什么SendNativeMessage说我尝试发送2G字节的消息?

Linux 为什么SendNativeMessage说我尝试发送2G字节的消息?,linux,firefox-addon,Linux,Firefox Addon,我尝试向Linux-Debian-Stretch-64位下的python3程序发送消息,该程序带有Firefox56附加组件。使用port.postMessage()函数,它可以工作,但我需要异步程序,因此我使用sendNativeMessage(),但即使程序可以工作,我也有以下消息: 本机应用程序尝试发送1990837074字节的消息,该消息 超过1048576字节的限制。NativeMessaging.jsm:283 _startRead/this.readPromise< resourc

我尝试向Linux-Debian-Stretch-64位下的python3程序发送消息,该程序带有Firefox56附加组件。使用port.postMessage()函数,它可以工作,但我需要异步程序,因此我使用sendNativeMessage(),但即使程序可以工作,我也有以下消息:

本机应用程序尝试发送1990837074字节的消息,该消息 超过1048576字节的限制。NativeMessaging.jsm:283 _startRead/this.readPromise< resource://gre/modules/NativeMessaging.jsm:283:11

我的背景课程:

var port = browser.runtime.connectNative("gettext");
var first = 0
var portFromCS;

function onExecuted(result) {
  console.log(`appel au content-script fait`);
}

function onError(error) {
  console.log(`Error: ${error}`);
}


browser.commands.onCommand.addListener(function(command) {
  if (command == "toggle-feature") {
    console.log("toggling the feature!");
    var executing = browser.tabs.executeScript({ file: "/content-script.js",  allFrames: false });
    executing.then(onExecuted, onError);
  }
});

function onSend(response) {
  console.log("recu du python" + response);
}

function onBug(error) {
  console.log(`Error python: ${error}`);
}


function connected(p) {
  portFromCS = p;

  portFromCS.onMessage.addListener(function(m) {
      console.log("longueur message = " + m.length)
      if ( m.length > 1 && m.charAt(0) > 'а' && m.length < 100)  {
        var sending = browser.runtime.sendNativeMessage("gettext",m);
        sending.then(onSend, onBug);
      }
  });

}

browser.runtime.onConnect.addListener(connected);

/*
port.onMessage.addListener((response) => {
  console.log("Recu de python" + response);
});*/
内容脚本:

var selectedText = getSelection().toString();

var myPort = browser.runtime.connect({name:"port-from-cs"});

myPort.postMessage(selectedText);
Manifest.json:

{

  "description": "Native messaging and Hotkey and content-script messaging",
  "manifest_version": 2,
  "name": "getSelectedTextFromHotkey",
  "version": "1.0",
  "icons": {
    "48": "icons/message.svg"
  },

  "applications": {
    "gecko": {
      "id": "gettext@example.org",
      "strict_min_version": "50.0"
    }
  },

  "background": {
    "scripts": ["background.js"]
  },

  "commands": {
  "toggle-feature": {
    "suggested_key": {
      "default": "Ctrl+Shift+4",
      "linux": "Ctrl+Shift+5"
    },
    "description": "Send the selected text"
  }
},


  "browser_action": {
    "default_icon": "icons/message.svg"
  },

 "content_scripts": [
  {
    "matches": ["<all_urls>"],
    "js": ["content-script.js"]
  }

  ],

  "permissions": [ "<all_urls>","nativeMessaging","webRequest"]

}
{
“说明”:“本机消息、热键和内容脚本消息”,
“清单版本”:2,
“名称”:“getSelectedTextFromHotkey”,
“版本”:“1.0”,
“图标”:{
“48”:“icons/message.svg”
},
“应用程序”:{
“壁虎”:{
“id”:”gettext@example.org",
“严格的最低版本”:“50.0”
}
},
“背景”:{
“脚本”:[“background.js”]
},
“命令”:{
“切换功能”:{
“建议的_键”:{
“默认值”:“Ctrl+Shift+4”,
“linux”:“Ctrl+Shift+5”
},
“说明”:“发送所选文本”
}
},
“浏览器操作”:{
“默认图标”:“icons/message.svg”
},
“内容脚本”:[
{
“匹配项”:[“”],
“js”:[“content script.js”]
}
],
“权限”:[“”、“nativeMessaging”、“webRequest”]
}
python程序提供正确的信息,不向后台程序发送信息。因此,我认为问题来自background.js


你知道错误在哪里吗?

迟到总比不到好

由于应用程序不回复消息,Firefox会读取整个stdin缓冲区(或其他内容),以搜索有效的响应消息。它读取的缓冲区超过了最大大小(可能由操作系统决定)。由于仍然找不到有效消息,Firefox假定应用程序发送了大量消息并抛出错误

这也可能是由响应无效消息引起的


解决方案:使用有效的邮件回复(即使用
encodeMessage
编码并使用
sendMessage
发送)

请回答主题中的问题:包括与问题重复的问题。对于Chrome扩展或Firefox WebExtensions,您几乎总是需要包含manifest.json和一些背景、内容和/或弹出脚本/HTML,通常还有网页HTML/scripts。寻求调试帮助的问题(“为什么我的代码没有按我想要的方式工作?”)必须包括:(1)所需的行为,(2)特定的问题或错误,(3)在问题本身中重现它所需的最短代码。另请参阅:、和。鉴于错误至少表明发送大量数据的是您的本机应用程序,我们也需要它(作为源代码)。我的应用程序不发送消息我遇到了相同的问题(3小时试图解决它),结果是,在我的情况下,我正在将日志打印到控制台。如果代码和你说的一模一样,我看不到日志。。。这意味着这不是发生在我身上的事。如果你只是举个例子,在你的实际代码中,你正在把东西打印到屏幕上,那就是错的。我知道这可能太晚了,但如果有帮助的话,我什么都不用花。祝你好运
{

  "description": "Native messaging and Hotkey and content-script messaging",
  "manifest_version": 2,
  "name": "getSelectedTextFromHotkey",
  "version": "1.0",
  "icons": {
    "48": "icons/message.svg"
  },

  "applications": {
    "gecko": {
      "id": "gettext@example.org",
      "strict_min_version": "50.0"
    }
  },

  "background": {
    "scripts": ["background.js"]
  },

  "commands": {
  "toggle-feature": {
    "suggested_key": {
      "default": "Ctrl+Shift+4",
      "linux": "Ctrl+Shift+5"
    },
    "description": "Send the selected text"
  }
},


  "browser_action": {
    "default_icon": "icons/message.svg"
  },

 "content_scripts": [
  {
    "matches": ["<all_urls>"],
    "js": ["content-script.js"]
  }

  ],

  "permissions": [ "<all_urls>","nativeMessaging","webRequest"]

}