I am working on this application that is sort of a plugin which is embedded in a website to track website changes, We use to override prototype implementation of send and fetch in the below fashion. Then piece of code that looks like this.
var v = window.XMLHttpRequest.prototype.send;
window.XMLHttpRequest.prototype.send = function (w) {
this.addEventListener("load", function (T) {
// custom logic
});
return v.apply(this, arguments)
}
This works like a piece of cake for many customers but for one we are facing issue where the debugger doesn't reach above piece of code resulting in failure to set the custom logic.
On further debugging we noticed that the customer also overrides the XMLHttpRequest.prototype.open method and has a custom logic to send this data to their internal CRM/webhook.
This is their implementation.
const open = window.XMLHttpRequest.prototype.open;
function customActivityHandler() {
this.addEventListener("load", function () {
// custom logic
log_custom_activity_event({})
return open.apply(this, arguments);
}
window.XMLHttpRequest.prototype.open = customActivityHandler;
function log_custom_activity_event(requestBody) {
let url = "https://aws.lambda.com/webhook";
let dataBody = {
method: "POST",
body: JSON.stringify(requestBody)
}
fetch(url,dataBody);
}
This step is very crucial for me.
By any chance when the client implementation their customHandler for open does it dereferences other implementation ? If thats the case how can i fix this so that even my custom logic is applied. Any thing on this will be helpful.