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

136
Vistas
Overwriting XMLHttpRequest.prototype.send breaks after navigating via breadcrumbs menu

We're working with a custom frontend framework that's based on PrimeFaces/JSF.

Lately, we added a display that shows how long until the user gets logged out due to inactivity. To correctly reset the countdown on user activity, I've overwritten the XMLHttpRequest.prototype.send method via JavaScript:

var minutesUntilTimeout = 60;
var logoutAt = minutesUntilTimeout * 60 * 1000 + new Date().getTime();

var send = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.send = function(data) {
    send.call(this, data);
    logoutAt = minutesUntilTimeout * 60 * 1000 + new Date().getTime();
}

This works correctly as it is.

However, we encountered a problem: The JS code gets executed on page load, and to work correctly, it is mandatory that XMLHttpRequest.prototype.send contains the original functionality. However, sometimes it still contains our overwritten function from the last JS execution (e.g. when we get to a page via the breadcrumb menu). This breaks the application, since every user action that uses XMLHttpRequest.prototype.send will trigger the overwritten function, that internally calls the var send "original" function, which is the same function in this special case, creating an infinite loop. I think it has to do with the HTTP request, since as far as I remember, the breadcrumbs use GET and all buttons, main menu etc. use POST (but this is just a guess, I'm not that deep into the implementation details of our framework).

Is there any way to ensure that XMLHttpRequest.prototype correctly resets on ALL page changes, aside from simply avoiding the breadcrumbs?

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

0

Once again, the rubber duck principle holds true - minutes after posting, I found a workaround. In case anyone ever needs it, I added a case differentiation:

if (typeof XMLHttpRequest.prototype.oldSend !== "function") {
    XMLHttpRequest.prototype.oldSend = XMLHttpRequest.prototype.send;
    XMLHttpRequest.prototype.send = function(data) {
        XMLHttpRequest.prototype.oldSend.call(this, data);
        logoutAt = minutesUntilTimeout * 60 * 1000 + new Date().getTime();
    }
}
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