Javascript firefox扩展,用于记录每个选项卡的http请求URL
我正在尝试开发一个firefox扩展来记录每个浏览器选项卡/窗口的所有资源加载URL。我搜索了几个小时,但找不到将每个拦截的http请求与其原始选项卡关联的方法。这是我到目前为止所拥有的Javascript firefox扩展,用于记录每个选项卡的http请求URL,javascript,firefox,firefox-addon,Javascript,Firefox,Firefox Addon,我正在尝试开发一个firefox扩展来记录每个浏览器选项卡/窗口的所有资源加载URL。我搜索了几个小时,但找不到将每个拦截的http请求与其原始选项卡关联的方法。这是我到目前为止所拥有的 Components.classes["@mozilla.org/observer-service;1"] .getService(Components.interfaces.nsIObserverService) .addObserver({ observe: function(aSubjec
Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService)
.addObserver({
observe: function(aSubject, aTopic, aData) {
if ("http-on-modify-request" == aTopic) {
var url = aSubject
.QueryInterface(Components.interfaces.nsIHttpChannel)
.originalURI.spec;
alert(url);
}
}
}, "http-on-modify-request", false);
我可以获取http请求的url,但我不知道有什么方法可以将其链接到浏览器窗口/选项卡
我通读了MDN的文档,但没有提到它。(https://developer.mozilla.org/en/XUL_School/Intercepting_Page_Loads)
有什么建议吗?我对的回答几乎可以让你达到目的。您将获得与请求关联的窗口,但它可能是选项卡中的一个框架。一旦你有了它,你可以得到
窗口。top
-这将是浏览器选项卡中的顶部窗口。如果您需要实际的浏览器选项卡元素,可以在中使用我的答案。。您将获得与请求关联的窗口,但它可能是选项卡中的一个框架。一旦你有了它,你可以得到窗口。top
-这将是浏览器选项卡中的顶部窗口。如果您需要实际的浏览器选项卡元素,您可以使用我的答案。如果您希望构建扩展,不仅是Firefox,而且是Chrome、IE和Safari的扩展,只需1个(javascript)代码,我建议您使用
你可以很容易地实现你想要的。
您可以使用onRequest API侦听所有发出的请求:
appAPI.onRequest(function(resourceUrl, tabUrl) {
// Where:
// * resourceUrl contains the URL of the requested resource
// * tabUrl contains the URL of the tab requesting the resource
// Block the loading of js scripts
if (resourceUrl.match(/.*/) {
// Do what ever you need with the specific resource
// For example - save it in the extension database using appAPI.db.set()
}
});
进入扩展的background.js,并允许您在每个页面/选项卡的每个加载资源上执行任何操作。如果您希望构建扩展,不仅针对Firefox,而且针对Chrome、IE和Safari,仅使用1(javascript)代码,我建议您使用 你可以很容易地实现你想要的。 您可以使用onRequest API侦听所有发出的请求:
appAPI.onRequest(function(resourceUrl, tabUrl) {
// Where:
// * resourceUrl contains the URL of the requested resource
// * tabUrl contains the URL of the tab requesting the resource
// Block the loading of js scripts
if (resourceUrl.match(/.*/) {
// Do what ever you need with the specific resource
// For example - save it in the extension database using appAPI.db.set()
}
});
进入扩展的background.js,允许您对每个页面/选项卡的每个已加载资源执行任何操作