Ich versuche, Rückrufe in XMLHttpRequest.prototype.open()
zu injizieren, so kann ich die Methode und die URL kennen, sowie einen Zeitstempel für den Leistungsbericht Einstellung (allein mit dem modifizierten XMLHttpRequest.prototype.send()
).Ist es möglich, XMLHttpRequest.prototype.open() zu ändern?
Hier ist, was ich bisher kam:
function addXMLRequestCallback(open, callback) {
var nativeOpen, nativeSend, i;
if (XMLHttpRequest.callbacks) {
XMLHttpRequest.callbacks.push(callback);
} else {
XMLHttpRequest.callbacks = [callback];
nativeOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function() {
open.forEach(function(item) {
// not sure what to do here...
});
}
nativeSend = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.send = function() {
for (i = 0; i < XMLHttpRequest.callbacks.length; i++) {
XMLHttpRequest.callbacks[i](this);
}
nativeSend.apply(this, arguments);
}
}
}
addXMLRequestCallback(function(method,url){
// Maybe instead I should put code here...
}, function(xhr) {
// then do something here?
});
Nun tun Sie es einfach auf die gleiche Weise mit 'send' tat. Wir wissen auch nicht, was wir dort tun sollen, was willst du tun? – Bergi