如何从 Greasemonkey 脚本拦截 XMLHttpRequests? [英] How can I intercept XMLHttpRequests from a Greasemonkey script?

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

问题描述

我想使用 Greasemonkey 捕获 AJAX 请求的内容.

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

有人知道怎么做吗?

推荐答案

接受的答案几乎是正确的,但可以稍微改进一下:

The accepted answer is almost correct, but it could use a slight improvement:

(function(open) {
    XMLHttpRequest.prototype.open = function() {
        this.addEventListener("readystatechange", function() {
            console.log(this.readyState);
        }, false);
        open.apply(this, arguments);
    };
})(XMLHttpRequest.prototype.open);

更喜欢使用 apply + 参数而不是调用,因为这样您就不必明确知道提供给 open 的所有参数,这些参数可能会改变!

Prefer using apply + arguments over call because then you don't have to explicitly know all the arguments being given to open which could change!

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

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