Firefox addon 我可以在附加SDK中侦听XUL类型的事件吗

Firefox addon 我可以在附加SDK中侦听XUL类型的事件吗,firefox-addon,firefox-addon-sdk,Firefox Addon,Firefox Addon Sdk,我正在尝试收听显示授权要求对话时发生的事件,请参见 然而,我注意到XUL插件可以监听DomWillOpenModelDialog事件,该事件显然是在该对话框打开时触发的。似乎未触发任何SDK面板事件 有没有办法从插件SDK中侦听此事件 ---编辑--- 从诺伊蒂达特的建议开始,我尝试了一些其他的活动,结果他们开火了。以下两种尝试都有效 var events = require("sdk/system/events"); function listener(event) {console.log(

我正在尝试收听显示授权要求对话时发生的事件,请参见

然而,我注意到XUL插件可以监听DomWillOpenModelDialog事件,该事件显然是在该对话框打开时触发的。似乎未触发任何SDK面板事件

有没有办法从插件SDK中侦听此事件

---编辑---

从诺伊蒂达特的建议开始,我尝试了一些其他的活动,结果他们开火了。以下两种尝试都有效

var events = require("sdk/system/events");
function listener(event) {console.log("An event popup was activated.");}
events.on("xul-window-visible", listener);

CWin.addEventListener("DOMWillOpenModalDialog", function() {CWin.setTimeout(NfyBox, 500);}, true);
function NfyBox() {
console.log("An event popup was activated.");
worker = tabs.activeTab.attach({
    contentScriptFile: self.data.url("notifybox.js")
});
worker.port.emit("notify");
}
然而,就我所知,在contentScriptFile中,文档的console.log会生成:-

console.log: infstr: {"location":{"assign":"function assign() {\n    [native cod
e]\n}","replace":"function replace() {\n    [native code]\n}","reload":"function  
reload() {\n    [native code]\n}","toString":"function toString() {\n    [nativ
e code]\n}","valueOf":"function valueOf() {\n    [native code]\n}","href":"http:
//c1s4-1e-syd.hosting-services.net.au:2082/unprotected/redirect.html","origin":"
http://c1s4-1e-syd.hosting-services.net.au:2082","protocol":"http:","username":"
","password":"","host":"c1s4-1e-syd.hosting-services.net.au:2082","hostname":"c1
s4-1e-syd.hosting-services.net.au","port":"2082","pathname":"/unprotected/redire
ct.html","search":"","hash":""}}

但是尝试获取getElementById或我尝试的任何其他内容都没有定义。我显然犯了一些简单的错误,但看不出是什么。

是的,请收听弹出事件。在这种情况下,弹出显示:

这是一个通过监听popuphiding并阻止关闭右上角三条菜单按钮的主菜单的示例:

var PUI = Services.wm.getMostRecentWindow('navigator:browser').document.querySelector('#PanelUI-popup');
try {
PUI.removeEventListener('popuphiding', previt, false);
} catch (ignore) {}
    var previt = function(e) {
    PUI.style.opacity = 1;
    e.stopPropagation();
    e.preventDefault();
    e.returnValue = false;
    return false;
}
PUI.addEventListener('popuphiding', previt, false); 

谢谢你,不幸的是,我不能让它工作。我试过:-但没有结果。不过,你确实让我尝试了一些其他的东西,这让我看得更远一些question@BushAl更改var{Services}=Cu.import'resource://gre/modules/Services.jsm'; 只需Cu.import'resource://gre/modules/Services.jsm';谢谢你的耐心。我对插件和js都是新手。我在main.js中插入了代码,并且理解了为什么PUI为null没有加载页面,所以尝试如下,但PUI始终为null。为了清楚起见,可以访问lelal.com/cpanel Cu.import'resource://gre/modules/Services.jsm'; tabs.onready,logURL;函数logURLtab{console.logtab.url;var PUI=Services.wm.getMostRecentWindow'navigator:browser'.document.querySelector'Pa‌​nelUI popup';PUI.addEventListener'popupshowing',函数{console.logA popup已激活。},false;}@BushAl PUI实际上在窗口上,它不检查页面选项卡内容,因此只要主浏览器窗口在那里,它就会工作。但是,如果没有任何带有主菜单的窗口,则Is Services.wm.getMostRecentWindow'navigator:browser'可以为空。所以检查var recentWin=Services.wm.getMostRecentWindow'navigator:browser';如果recentWin{var PUI=recentWindow.getElementById'PanelUI';}否则{Services.prompt.alertnull'error',no browser window'}const{Cc,Ci,Cu}=requirechrome;特写:进口'resource://gre/modules/Services.jsm'; var recentWin=Services.wm.getMostRecentWindow'navigator:browser';如果recentWin{var PUI=recentWin.document.getElementById'PanelUI';如果PUI{PUI.addEventListener'popupshowing',函数{console.logA Popup被激活。},false;}否则{Services.prompt.alertnull',error',No PanelUI';}否则{Services.prompt.alertnull error',No browser window