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

133
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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