Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

131
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!