Tool to stop automatic logouts on websites

In the web application where I work, users are automatically logged out after a period of inactivity. Unfortunately, I am unable to control this feature. The code responsible for logging the user out is as follows:

var windoc = window.document;
var timeoutID;

function AlertUser() {
    var msg = 'Session expires in 90 seconds. Continue with this session?';
    var preConfirmTime = new Date();
    if (confirm(msg)) {
        var postConfirmTime = new Date();
        if (postConfirmTime.getTime() - preConfirmTime.getTime() > 90000) {
            alert('Sorry, your session has already expired.');
            window.location = '/Logout.aspx';
        } else {
            var img = new Image(1,1);
            img.src = '/Reconnect.aspx';
            timeoutID = window.setTimeout('AlertUser()','3510000'); 
        }
    } else {
        window.location = '/Logout.aspx';
    }
}

function ResetTimeout(delay) {
    window.clearTimeout(timeoutID);
    timeoutID = window.setTimeout('AlertUser()', delay);
}

timeoutID = window.setTimeout('AlertUser()','3510000');

Considering that these sudden logouts disrupt my workflow, I am interested in creating a bookmarklet that will automatically click `OK` when the session is about to expire. My initial idea was to use the following script:

javascript:window.confirm = function(){return true;};

However, this script only runs upon clicking the bookmarklet. Is there a way to make it automatically execute in the active browser tab (especially on IE 10), such as continuously checking for session expiration even when opening a new tab without the need for installing browser extensions? Please note that my primary method of interacting with webpages is through bookmarklets.

Answer №1

To modify the application being delivered to your browser, consider utilizing software such as Charles Proxy with its "Rewrite" feature if you have the ability to install programs locally. By defining a rewrite rule in Charles Proxy, you can consistently alter the application while Charles is active.

Answer №2

It seems like the issue you are experiencing could be caused by the following:

  1. When you use the bookmarklet, it stops the current page from logging out.
  2. If you right click or press ctrl+click on a link in the current page to open a new tab, that new tab might end up logging you out eventually.

A potential solution could involve modifying the bookmarklet so that it adds a click event listener to every link on the page. If the listener detects a CTRL+click, it can prevent the default action, open a new window using window.open, and apply necessary modifications in the new tab.

To avoid encountering the same issue when reloading or navigating within the same tab, the bookmarklet could create a small child window that monitors its parent. If the monitor notices that the parent is no longer properly modified, it can reapply the code.

One concern worth considering is whether the current solution will remain effective if the page is left idle for an extended period. The server may have its own session timeout, independent of client-side modifications. To address this, implementing a timer to perform periodic background page fetches via AJAX could help prevent any unexpected logouts.

Answer №3

Timeouts can be tricky to manage, especially when dealing with different components. The first part of the timeout is the AlertUser which activates after 58 minutes and 30 seconds. The second part involves the server's session timeout, which can apparently be refreshed by sending a GET request to /Reconnect.aspx.

While the ResetTimeout function helps handle the AlertUser timeout, it doesn't address the server-side session timeout. Using this as a starting point, we can take proactive measures:

setInterval(function(){
    clearTimeout(timeoutID);     // prevent the AlertUser from triggering
    var img = new Image(1,1);
    img.src = '/Reconnect.aspx'; // prevent the server session from expiring
},15*60*1000);

This approach aims to eliminate all potential timeouts. Although you might consider placing the clearTimeout outside the setInterval, incorporating it within the loop ensures added security in case there are code variations on the page resetting the AlertUser timeout.

The setInterval function operates every 15 minutes (15*60*1000), which is four times more frequent than the 58-minute page timeout. Adapting the interval time allows flexibility for adjusting to any changes in the page timeout duration, but avoid setting it too frequently to prevent being flagged as spam.

Another consideration is guarding against accidentally loading the bookmarklet twice. To enhance safety, begin by clearing any existing setInterval instances:

if (typeof anti_timeout != 'undefined') {
    clearInterval(anti_timeout);   // clear any previous anti-timeout timers
}
anti_timeout = setInterval(function(){
    clearTimeout(timeoutID);
    var img = new Image(1,1);
    img.src = '/Reconnect.aspx';
},15*60*1000);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Working with floating point numbers in Node.js with a zero decimal place

NodeJS interprets float values with a zero after the decimal point as integers, but this behavior occurs at the language level. For example: 5.0 is considered as 5 by NodeJS. In my work with APIs, it's crucial for me to be able to send float values w ...

Is there a way to fix the error "The requested resource does not have the 'Access-Control-Allow-Origin' header" within Express using Firebase functions?

Trying to send an email through nodemailer using Firebase functions, but encountering errors. The data for the email will come from a form. Error message: Access to XMLHttpRequest at 'my-firebase-functions' from origin 'my-angular-web-app&a ...

What could be causing the error when attempting to release this Node-MySQL pool?

My first attempt at utilizing connection pooling is with Node.js. I crafted a database connection module in Node.js to establish a single connection, which is then referenced within a pooling function for later use when passed to different modules. /* D ...

Angular dynamically selects a dropdown option when the page is loaded

Check out this dropdown example: <div class="col-md-6"> <div class="form-group> <label class="control-label">Role</label> < ...

Ajax - Trouble with Updating DIV Content

As a beginner in AJAX, I am encountering difficulties creating a simple AJAX program. My goal is to have a button that, when clicked, changes the text of the div below it. Despite numerous attempts, I have not been able to identify the issue. Below is the ...

Determining When the Collapse Transition in Material UI 5 is Complete

Snippet <Collapse in={expanded} onTransitionEnd={() => console.log('finished')} > <div>foo</div> </Collapse> Error Detection The callback function (onTransitionEnd) is not triggered af ...

What is the process for transferring a file's contents to my server?

I am currently working on allowing users to import an OPML file that I parse server-side in my Rails application. However, I am facing difficulties as it appears that my server is not receiving the information correctly (neither the success nor error funct ...

When querying parameters within a URL, you may encounter JavaScript (Node) errors

My current setup involves using Firebase Cloud Functions, but I have run into an issue. Whenever a parameter with a # symbol is received, it does not get recognized. For instance: http://example.net?id=123#456. When I check the logged id, only 123 is disp ...

What is the best way to create a feature in Vue that filters options in real-time as we type into a

In my Vue application, I am trying to implement dynamic filtering for the options in a search box as the user types. Currently, the search box displays the entire list of options without any filtering happening even when the user is typing. <el-form-it ...

Discover the security vulnerabilities in Node.js when using VS Code with FREECODECAMP's React app

As a beginner in using VS code, I attempted to work on a project for FREECODECAMP. This project involved creating a random quote machine, marking my first time coding a react project. While following a YouTube tutorial and making progress towards functiona ...

The error code 405 (Method Not Allowed) occurs in Ajax when the action field is empty or identical to the current page

Special thanks to @abc123 for sharing the code below in one of their posts: <!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery-1.9.1.js"></script> </head> <body> <form id="formoid" a ...

Encountering a mysterious error while attempting to access and modify a value stored in a useState hook using the keydown

I've been attempting to create a simple animation on canvas using React.js, but I'm facing an issue with integrating my Keydown function with my useState. It seems that my useState value is not being defined properly, preventing me from changing ...

What is the best way to incorporate component-specific CSS styles in React?

This is the layout that I am attempting to replicate (originally from react-boilerplate): component |Footer |style.css |Footer.js In Footer.js, the styles are imported in a very elegant manner like this: import React from 'react'; im ...

What is the best way to display an error message when a necessary field is left empty?

I am currently utilizing a plugin to validate my form. My goal is to display an error message on the button when clicked, as all fields in my form are required and need validation. Despite attempting the code below, it hasn't been successful: <Fo ...

Angular 4 in combination with ngx-datatable is showing a 404 error for the @swimlane/ngx-datatable package

Just starting out with Angular and I kicked things off by running this command: git clone https://github.com/angular/quickstart appName I've made the upgrade to Angular 4 and everything seems to be in order. Here's the output I got after running ...

Redirecting pages using an Ajax script in JavaScript

Unfortunately, I am unable to use a *.php extension for my page due to unforeseen circumstances. This has led me to consider using *.html instead and implementing conditional redirection using javascript/Ajax to call a PHP script that can evaluate the cond ...

Load External HTML content into webpage along with executing JavaScript code and triggering JS functions upon loading

I'm in search of a super lightweight solution that can effectively load an external HTML file into a page using only vanilla JavaScript. The external file contains HTML, CSS, and JS. Essentially, I want to create a concise JS snippet that loads a butt ...

Setting up React Router in a nested directory with a flexible route structure

As a newcomer to react router, I am seeking guidance on setting it up in a specific scenario. Imagine we have a PHP application running on 'http://www.example.com'. Within this setup, there is a react application located at 'http://www.examp ...

What is the best way to incorporate interactive columns in DataTables?

I am utilizing jquery datatables to present data. <table class="report-tbl table-bordered" cellspacing="0" width="100%" id="report-tbl"> <thead> <tr> <th></th> ...

Issue with ion-content on Ionic app not scrolling down when keyboard is displayed on an Android device

Currently, I am facing an issue with a basic view that contains a login form. When the keyboard pops up on Android devices, the content does not scroll up to ensure it remains visible above the keyboard. I have diligently followed the Keyboard instruction ...