Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

162
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda