我正在捕獲Firefox插件SDK擴展中的HTTP請求。我需要獲取與請求關聯的DOM窗口。但是,我收到一個NS_NOINTERFACE
錯誤。Firefox插件獲取發出HTTP請求的DOM窗口
這裏是我的代碼:
var httpRequestObserver = {
observe: function (subject, topic, data) {
var httpRequest = subject.QueryInterface(Ci.nsIHttpChannel);
var requestUrl = subject.URI.host;
var domWin;
var assWindow;
console.log('URL: ', requestUrl);
try {
domWin = httpRequest.notificationCallbacks.getInterface(Ci.nsIDOMWindow);
assWindow = httpChannel.notificationCallbacks.getInterface(Ci.nsILoadContext)
.associatedWindow;
console.log(domWin);
} catch (e) {
console.log(e);
}
// console.log('TAB: ', tabsLib.getTabForWindow(domWin.top));
var hostName = wn.domWindow.getBrowser().selectedBrowser.contentWindow.location.host;
console.log('HOST: ', hostName);
},
get observerService() {
return Cc['@mozilla.org/observer-service;1'].getService(Ci.nsIObserverService);
},
register: function() {
this.observerService.addObserver(this, 'http-on-modify-request', false);
},
unregister: function() {
this.observerService.removeObserver(this, 'http-on-modify-request');
}
};
httpRequestObserver.register();
我都試過nsIDOMWindow
和nsILoadContext
,但NS_NOINTERFACE
錯誤總是試圖得到window
對象出現。
*請*,[編輯]問題把控制檯消息信息**作爲文本,包含在'代碼塊**「中。如果錯誤生成了文本無法傳達的內容,那麼錯誤的圖像可能會有用。但是,在大多數情況下,擁有控制檯消息的圖像顯着比將其作爲文本更有用。以文本格式時,可以複製,粘貼和搜索。作爲文本,它們在回答這個問題和爲將來尋找類似問題的答案的人們提供了更多的幫助。 – Makyen
由於沒有將問題中包含的錯誤信息作爲文本進行投票,因此我投了票並投了票。如果您將錯誤信息作爲文本輸入到問題中,我將刪除我的倒票並收回我的近距離投票。在這種情況下,我可能會投票。請用'@ Makyen'發表評論,以便我收到變更通知。 – Makyen
@Makyen謝謝你的幫助,更新。 –