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

122
Vistas
Override post requests

I have this code that I put in my console:

XMLHttpRequest.prototype.send = function(body) {
    // modifies inputted request
    newBody = JSON.parse(body);
    newBody.points = 417;

  // sends modified request
    this.realSend(JSON.stringify(newBody));
}

It is supposed to make the points 417 every time it sends a request, but when I look at the request body, it still says the original amount of points. Any help?

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Try to add an alert() or console.log() into your modified XMLHttpRequest.prototype.send to check if it actually works. There is a way to prevent this kind of modifications silently.

about 4 years ago · Juan Pablo Isaza Denunciar

0

As others have noted, the error you are experiencing is hard to diagnose exactly without seeing how you created this.realSend.

However, this code will work:

const send = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.send = function (body) {
    const newBody = JSON.parse(body);
    newBody.points = 417;
    send.call(this, JSON.stringify(newBody));
};

Note that instead of storing the original send method on XMLHttpRequest.prototype, I've kept in a separate variable and simply invoked it with the correct this value through send.call(). This seems like a cleaner implementation with less chance for conflicts with other code.

See this codesandbox for a working example.

about 4 years ago · Juan Pablo Isaza Denunciar

0

If your function is not being called, possible fetch is used to make ajax requests.

So you can wrap both functions, like this

const send = XMLHttpRequest.prototype.send;
const _fetch = window.fetch;

XMLHttpRequest.prototype.send = function (body) {
   const newBody = JSON.parse(body);
   newBody.points = 417;
   send.call(this, JSON.stringify(newBody));
};

window.fetch = function(url, options){
   let newBody;
   if(options.body) {
      newBody = JSON.parse(options.body);
      newBody.points = 417;
      options.body = JSON.stringify(newBody);
   }
   _fetch.call(this, url, options);
}
about 4 years ago · Juan Pablo Isaza Denunciar
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