5 javascript firefox firefox-addon firefox-addon-sdk
我正在尝试使用以下代码将XMLHttpRequest与浏览器上的选项卡相关联:
function getBrowserFromChannel(aChannel) {
var notificationCallbacks =
aChannel.notificationCallbacks ?
aChannel.notificationCallbacks :
aChannel.loadGroup.notificationCallbacks;
if (!notificationCallbacks) {
console.log("no callbacks");
return (0);
}
var loadContext = notificationCallbacks.getInterface(Ci.nsILoadContext);
Run Code Online (Sandbox Code Playgroud)
getInterface(Ci.nsILoadContext)失败,并显示:"组件没有请求的接口"
知道我怎么能得到浏览器?
谢谢
试试这个代码(来自 Lightbeam):
function getLoadContext(aRequest) {
try {
// first try the notification callbacks
var loadContext = aRequest.QueryInterface(Ci.nsIChannel)
.notificationCallbacks.getInterface(Ci.nsILoadContext);
return loadContext;
} catch (ex) {
// fail over to trying the load group
try {
if (!aRequest.loadGroup) return null;
var loadContext = aRequest.loadGroup.notificationCallbacks.getInterface(Ci.nsILoadContext);
return loadContext;
} catch (ex) {
return null;
}
}
}
Run Code Online (Sandbox Code Playgroud)
请注意许可证是 MPL 1.1/GPL 2.0/LGPL 2.1
归档时间: |
|
查看次数: |
160 次 |
最近记录: |