Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

158
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda