Native app does not work in Chrome extension

纵然是瞬间 提交于 2019-12-03 23:10:12

By default cout is a text stream, sending null (that happens as part of your size first 4 bytes) ends your text stream early.

On Windows you can update cout to be binary by changing the underlying stdout, and don't forget to flush...

_setmode(_fileno(stdout), _O_BINARY);   
int len = msg.length();
std::cout << char(len >> 0)
  << char(len >> 8)
  << char(len >> 16)
  << char(len >> 24);

std::cout << msg << std::flush;
Mr.Deek

Example of a working script with Native reference. Note the Permissions for nativeMessaging and no direct reference to the external resource in the Manifest.json the reference is later on in the .js script.

{
   "background": {
      "scripts": [ "common.js", "filler.js",  "background.js" ]
   },
   "browser_action": {
      "default_icon": "r.png",
      "default_title": "Click this button to show commands"
   },
   "content_scripts": [ {
      "all_frames": true,
      "js": [ "common.js", "content.js", "filler.js" ],
      "matches": [ "http://*/*", "https://*/*", "file:///*" ],
      "run_at": "document_start"
   } ],
   "description": "For Google Chrome",
   "homepage_url": "http://www.app.com",
   "icons": {
      "128": "r.png",
      "16": "r.png",
      "32": "r.png",
      "48": "r.png"
   },
   "key": "???",
   "manifest_version": 2,
   "name": "???",
   "options_page": "options.html",
   "permissions": [ "tabs", "bookmarks", "webRequest", "webRequestBlocking", "nativeMessaging", "downloads", "http://*/*", "https://*/*" ],
   "update_url": "https://clients2.google.com/???/",
   "version": "???"
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!