[英]How to trace cors request using javascript
我们有通过cdn引用的第三方js
。 我们正在使用第三方服务来跟踪用户行为。 我们已经实现了从向不同域发送请求的 js 调用 function 的代码。 我们想使用 javascript 跟踪那些发送到不同域的请求。 如何使用 javascript 来做到这一点?
我试过下面的代码来跟踪请求,但它似乎只跟踪相同的域请求。
var open = window.XMLHttpRequest.prototype.open,
send = window.XMLHttpRequest.prototype.send;
function openReplacement(method, url, async, user, password) {
this._url = url;
console.log('url -------- ' + url);
return open.apply(this, arguments);
}
function sendReplacement(data) {
debugger;
console.log('data -------- ' + data);
return send.apply(this, arguments);
}
window.XMLHttpRequest.prototype.open = openReplacement;
window.XMLHttpRequest.prototype.send = sendReplacement;
如果您使用 jquery,它有一些全局 ajax function:例如:
let open = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function () {
this.addEventListener("load", event => function () {
console.log(event.target);
if (event.target.responseURL.indexOf('YourDomain')>-1) {
//Do Something
}
}, false);
open.apply(this, arguments);
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.