Firefox addon 加载XPCOMM对象

Firefox addon 加载XPCOMM对象,firefox-addon,Firefox Addon,我正在编写一个带有面板的Firefox扩展。 在那个面板里,我有一个启动记事本的按钮; 在bootstrap.js中,我有: const { classes: Cc, Constructor: CC, interfaces: Ci, utils: Cu, results: Cr, manager: Cm } = Components; panel.port.on("openNotepadd", function(){ try{ var file =

我正在编写一个带有面板的Firefox扩展。 在那个面板里,我有一个启动记事本的按钮; 在bootstrap.js中,我有:

const { classes: Cc, Constructor: CC, interfaces: Ci, utils: Cu,
        results: Cr, manager: Cm } = Components;
panel.port.on("openNotepadd", function(){


    try{

        var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
        console.log('1'); // Never got here

        file.initWithPath("c:\\windows\\system32\\notepad.exe");

        // create an nsIProcess
        var process = Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess);
        process.init(file);

        var args = [];
        process.run(false, args, args.length);


    }catch(e){
        alert(e.message);
    }

});
我补充说:

Components.utils.import("resource://gre/modules/Services.jsm");
在main.js中,我有以下内容:

const { classes: Cc, Constructor: CC, interfaces: Ci, utils: Cu,
        results: Cr, manager: Cm } = Components;
panel.port.on("openNotepadd", function(){


    try{

        var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
        console.log('1'); // Never got here

        file.initWithPath("c:\\windows\\system32\\notepad.exe");

        // create an nsIProcess
        var process = Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess);
        process.init(file);

        var args = [];
        process.run(false, args, args.length);


    }catch(e){
        alert(e.message);
    }

});

我没有发现任何错误,只是什么也没发生。这些代码有什么问题?

要获取
nsi文件,请执行以下操作:

Cu.import('resource://gre/modules/FileUtils.jsm');
var file = new FileUtils.File('C:\\blah.png');

但是要避免这种情况,nsIFile不像
OS.File
child\u进程那样对主线程友好。要获取
nsIFile
,请执行以下操作:

Cu.import('resource://gre/modules/FileUtils.jsm');
var file = new FileUtils.File('C:\\blah.png');

但是要避免这种情况,nsIFile不像
OS那样对主线程友好。文件
child\u进程

不要使用
nsIProcess
,而是使用
child\u进程
-@Noitidart,就像代码中提到的那样,从未通过“var File=…”对于child_process,您不需要nsifile,但我会发布如何获取nsifile的解决方案。不要使用
nsIProcess
,而是使用
child_process
-@Noitidart,正如代码中提到的,从未通过“var file=…”对于child_process,您不需要nsifile,但我会发布如何获取nsifile的解决方案。@DanielH现在试试,我在FileUtils.jsm@Noitidart的路径中输入了,我不明白你说的“我在通往@DanielH的路径中输入了”是什么意思,我是说“输入错误”,再试一次,会有用的。以前我有
resources:
但是没有复数形式,应该是
resource:
LOL,我不知道这是否符合除夕精神,但是你没有用复数形式发布,请看你的帖子,上面写着“Cu.import”resource://gre“。无论如何,我设法找到了问题,它应该是:require('chrome')。Cu.import('resource://gre/modules/FileUtils.jsm);我给了你分数,因为你努力帮助我,并为我指出了正确的方向。谢谢。哦,糟糕!完全忽略了这一点,是的,要在你的插件
var{Cu,Ci}=require('chrome')的顶部加上Cu,你需要加上Cu
然后你就可以做
Cu.
之类的事情了。干得好!@DanielH现在试试,我在FileUtils的路径上打了个字。jsm@Noitidart我不明白你说的“我在FileUtils的路径上打了个字”@DanielH我是说“打字错误”请再试一次。在我有
资源之前:
但是没有复数形式,它应该是
资源:
LOL,我不知道它是否符合除夕精神,但你没有用复数形式发布,请看你的帖子,上面写着“Cu.import.”resource://gre无论如何,我找到了问题所在,应该是:需要('chrome').Cu.import('chrome')resource://gre/modules/FileUtils.jsm);我给了你分数,因为你努力帮助我,并为我指出了正确的方向。谢谢。哦,糟糕!完全忽略了这一点,是的,要在你的插件
var{Cu,Ci}=require('chrome')的顶部加上Cu,你需要加上Cu
然后你就可以做
Cu.
之类的事了。干得好!