我怎么能拦截XMLHtt prequests从Greasemonkey的脚本? [英] How can I intercept XMLHttpRequests from a Greasemonkey script?

查看:162
本文介绍了我怎么能拦截XMLHtt prequests从Greasemonkey的脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想捕捉使用Greasemonkey的AJAX请求的内容。

I would like to capture the contents of AJAX requests using Greasemonkey.

是否有人知道如何做到这一点?

Does anybody know how to do this?

推荐答案

下面是在我的测试中表现一个小片段:

Here's a little snippet that worked in my tests:

(function(open) {

    XMLHttpRequest.prototype.open = function(method, url, async, user, pass) {

        this.addEventListener("readystatechange", function() {
            console.log(this.readyState);
        }, false);

        open.call(this, method, url, async, user, pass);
    };

})(XMLHttpRequest.prototype.open);

我用的addEventListener(),如果你想换onreadystatechange属性火狐引发异常。通过这种方式,你可以有一个蛋糕吃了。

I've used addEventListener() as Firefox throws an exception if you want to wrap the onreadystatechange property. This way you can have the cake an eat it too.

这篇关于我怎么能拦截XMLHtt prequests从Greasemonkey的脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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