从Chrome的nativeMessaging API调用节点应用程序

准系统样品

我有一个扩展,我加载在开发人员模式(已经尝试打包和解压扩展)。 它由三部分组成:

  1. 的manifest.json
  2. main.html中
  3. main.js

而一个应用程序本身由三部分组成:

  1. app.js
  2. app.bat
  3. node.json

希望的状态

当我从命令行运行node app.js ,程序按预期运行。

app.js源代码:

 var fs = require('fs'); var util = require('util'); var encoding = "utf8"; var launch = new Date(); var logFile = "C:\\Users\\Jason.Nichols\\Desktop\\Node\\log.txt" function fileLog(arg){ var d = new Date(); var e = d.toString() + " "; if(typeof arg != 'string'){ arg = util.inspect(arg) } fs.appendFileSync(logFile, " " + e + arg + "\n"); } fileLog("Process Launched"); try { process; fileLog("Process exists"); process.stdin.on('readable', function() { var chunk = process.stdin.read(); if (chunk !== null) { fileLog(chunk); process.stdout.write('{"data": "' + chunk +'"}'); } }); process.stdin.on('end', function() { fileLog("EOL") process.stdout.write('end'); }); fileLog("Resume") process.stdin.resume(); }catch(e){ fileLog(e); } fileLog("Leaving"); 

正如你所看到的,它并没有做任何事情,而在命令行中,它只是回应任何事情。

我可以在我的logfile.txt看到所有的logfile.txt ,并且通常会有欢乐。

然而…

当在我的扩展中运行时,我得到:

 18:06:21:031 Connecting to native messaging host com.google.chrome.node.sample 18:06:21:065 Completed connecting to native messaging host com.google.chrome.node.sample (31ms) 18:06:21:185 Failed to connect: Native host has exited. (150ms) 

在我的浏览器。

当我进一步检查fileLog每一件事,我发现,当铬通过app.bat运行文件,我的logFile得到以下错误:

 Mon May 12 2014 18:43:55 GMT-0400 (Eastern Daylight Time) { [Error: EINVAL, invalid argument] errno: 18, code: 'EINVAL', syscall: 'uv_pipe_open' } 

这当然不好。

我的问题:

什么是errno: 18 ,为什么只在Chrome中运行,而不是在命令行运行? 如果有任何帮助,我正在运行Win7x64,Chrome 34和节点0.10.26。

我的直觉是,这个问题与SIGPIPE或其他一些信号从Chrome浏览器发送到我的Node进程有关,但就我所知, 任何帮助将不胜感激,因为我从通过nativeMessage运行Python脚本(显然不是相同的错误代码,但浏览器触发onDisconnect事件及其绑定的侦听器)获得相同types的行为。

我已经设置了相应的registry值,其他文件可以在这里查看