我有一个扩展程序,我在开发人员模式下加载(尝试打包和解压扩展)。它由三部分组成:
一个应用程序本身由三部分组成:
当我从命令行运行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
中看到我的所有日志,通常会有欢乐。
在我的扩展程序的上下文中运行时,我得到:
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
进一步检查时,我发现当chrome通过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
事件及其绑定的侦听器)。
我已设置相应的注册表值,可以查看其他文件here