如何处理Firefox扩展中的每个请求? [英] How to handle every request in a Firefox extension?

查看:136
本文介绍了如何处理Firefox扩展中的每个请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图捕捉并处理每个请求的一个网页,或其中的插件即将作出。
例如,如果您打开控制台并启用网络日志记录,那么当HTTP请求即将发送时,控制台会在那里显示它。
我想要捕捉每一个链接并调用我的功能,即使是一个视频加载的Flash播放器(如果它是登录在控制台 http )。
任何人都可以引导我应该做什么,或者我应该从哪里开始?

编辑:我希望能够取消请求并处理它如果需要的话。

解决方案

我相信你可以使用Jetpack SDK来获取你所需要的大部分内容。如果您注册了系统事件并听取对于 http-on-modify-request ,您可以使用nsIHttpChannel方法修改回复和请求

  let {Ci} = require('chrome'); 
让{on} = require('sdk / system / events');
let {newURI} = require('sdk / url / utils'); ('http-on-modify-request',function({subject,type,data}){
if(/google/.test(subject.URI.spec))

{
subject.QueryInterface(Ci.nsIHttpChannel);
subject.redirectTo(newURI('http://mozilla.org'));
}
});

其他信息拦截页面加载


I'm trying to capture and handle every single request a web page, or a plugin in it is about to make. For example, if you open the console, and enable Net logging, when a HTTP request is about to be sent, console shows it there. I want to capture every link and call my function even when a video is loaded by flash player (which is logged in console also, if it is http). Can anyone guide me what I should do, or where I should get started?

Edit: I want to be able to cancel the request and handle it my way if needed.

解决方案

You can use the Jetpack SDK to get most of what you need, I believe. If you register to system events and listen for http-on-modify-request, you can use the nsIHttpChannel methods to modify the response and request

let { Ci } = require('chrome');
let { on } = require('sdk/system/events');
let { newURI } = require('sdk/url/utils');

on('http-on-modify-request', function ({subject, type, data}) {
  if (/google/.test(subject.URI.spec)) {
    subject.QueryInterface(Ci.nsIHttpChannel);
    subject.redirectTo(newURI('http://mozilla.org'));
  }
});

Additional info, "Intercepting Page Loads"

这篇关于如何处理Firefox扩展中的每个请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆