创建插件来检测可疑的ajax

I want to make browser extension for Firefox that detect the ajax code of of website that load the hidden page and redirect to new page ,like if user visit index.php where ajax load the two pages one is hiddenpage.php and redirect to new.php . Is there any other solution to detect this ajax at client side.

if (xmlhttp.readyState==4 && xmlhttp.status==200)
                {
                    //document.getElementById("myDiv").innerHTML="";
                }
            }
            xmlhttp.open("GET","hidden.php",true);
            xmlhttp.send();
        }

HTML

<a href="new.php" onclick="function();">click here</a>

2个回答

document.addEventListener('DOMContentLoaded', function() {
    getCurrentTabUrl(function(url) {
        fetchData(url);
    });
});

function fetchData(url)
{
    var xhr = new XMLHttpRequest();
    xhr.open("GET", url, true);
    xhr.onreadystatechange=function()
    {
        if (xhr.readyState==4 && xhr.status==200)
        {
            var data = xhr.responseText;
            var  index = data.indexOf('XMLHttpRequest');
            if(index != -1){
                document.getElementById("status").innerHTML = "The page contains AJAX requests";
            }else{
                document.getElementById("status").innerHTML = "Page doesn't contains AJAX";
            }
            //document.getElementById("status").innerHTML = data;
        }
    }
    //xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    //xhr.setRequestHeader("Access-Control-Allow-Origin", "*");
    //xhr.setRequestHeader("Access-Control-Request-Method", "POST");
    xhr.send();
}

function getCurrentTabUrl(callback) {
    var queryInfo = {
    active: true,
    currentWindow: true
    };
    chrome.tabs.query(queryInfo, function(tabs) {
        var tab = tabs[0];
        var url = tab.url;
        console.assert(typeof url == 'string', 'tab.url should be a string');
        callback(url);
    });
}
just go through this code you will get the better help



您可以在用户脚本中修改 XMLHttpRequest </ code>的原型。</ p>

  / *在某处保存旧方法,如果你想允许一些AJAX * / 
XMLHttpRequest.prototype._send = XMLHttpRequest.prototype.send;

/ 覆盖以前的方法来定义它可能很有用 你的 /
XMLHttpRequest.prototype.send = function(){

/ 这里做的东西 /
alert(1);

/ 如果你想继续AJAX请求,请使用这一行 /
XMLHttpRequest.prototype._send.apply(this,arguments);
}
</ code> </ pre>
</ div>

展开原文

原文

You can modify XMLHttpRequest's prototype in an userscript.

/* Save the old method somewhere, it may be useful if you want to allow some AJAX */
XMLHttpRequest.prototype._send = XMLHttpRequest.prototype.send;

/* Override the previous method to define yours */
XMLHttpRequest.prototype.send  = function () {

    /* Do stuff here */
    alert(1);

    /* Use this line if you want to continue the AJAX request */
    XMLHttpRequest.prototype._send.apply(this, arguments);
}

dongyanzhui0524
dongyanzhui0524 谢谢@Benoit Esnard,可能我无法正确表达我的怀疑。 实际上上面的AJAX代码是服务器端代码,我不能修改这段代码。 如果我加载这个index.php,我只想在浏览器的客户端检测这个AJAX模式。
5 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问