网页请求hook 函数
// 保存原始的 XMLHttpRequest 对象
var originalXHR = window.XMLHttpRequest;
// 创建新的 XMLHttpRequest 对象,继承自原始的 XMLHttpRequest
function ProxyXHR() {
var xhr = new originalXHR();
// 重写 open 方法
var originalOpen = xhr.open;
xhr.open = function(method, url, async) {
// 这里可以进行你的自定义处理
console.log('XHR request intercepted:', method, url);
// 调用原始的 open 方法
originalOpen.apply(this, arguments);
};
// 返回新的 XMLHttpRequest 对象
return xhr;
}
// 替换全局的 XMLHttpRequest 对象为代理对象
window.XMLHttpRequest = ProxyXHR;