Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

160
Views
Overriding XMLHttpRequest.prototype.send

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.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!