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

IE11 Error: Script1003 expected but not found

I'm in the process of adding IE11 support, but encountering the following errors: SCRIPT1003: Expected ':' File: vendor.bundle.js, Line: 8699, Column: 8 SCRIPT5009: 'webpackJsonp' is undefined File: app.bundle.js, Line: 1, Colum ...

Tips for verifying the rendered view post data retrieval from an API in Vue JS

Having trouble retrieving data from the API using Vue JS and printing the page? After fetching the data, some elements may not render completely when trying to print, resulting in blank data being displayed. While using a setTimeout function may work for s ...

Incorporating Recoil with React, a substantial array is experiencing lags due to numerous re-renders

I currently have an array of around 400 objects within my application. The hierarchy of components in my tree is structured as follows: App -> Page (using useRecoilState(ListAtom) for consumption) -> List -> Item (utilizing useSetRec ...

Beginning a counter: a step-by-step guide

I am currently utilizing Angular to create a functional counter like so: <button ng-click="order.startOperation(operation)"> <p ng-if="counter.start"></p> </button> When the button is clicked, it triggers a function that initia ...

The concept of CSS "preload" animation

When working with CSS, I encountered an issue with lag while loading 24 different mask images for a transition effect. To address this, I tried using a div called "preload" to cache the images and prevent lag on playback: <div class='trans' s ...

Avoid opening the page when attempting to log in with jquery, ajax, and php

I am facing an issue with my code. I have a file named "index.html" which contains a login form. Another file called "dash.js" retrieves the username and password from the login form and redirects to "connectdb.php" to check the login credentials with the ...

What is the primary function for Express.js and Node.js 10 in Google Cloud Functions?

My Node JS version is 10 Express JS version: 4.16.1 I understand that for Node JS 8, the entry point should be "app" The generated code (from `npm install -g express-generator) www #!/usr/bin/env node /** * Module dependencies. */ var app = require( ...

"Combining HTML, PHP, and JavaScript for Dynamic Web

Here is the PHP function that retrieves the visitor's profile image thumbnail: <?php echo voip_profile_image($visitorid,'thumb'); ?> The issue lies in the fact that $visitorid is stored in JavaScript under the sRemoteid parameter. Wi ...

What is the best way to link a dynamic property with a bootstrap popover within a nested v-for loop?

After spending several days searching for an example to guide me without success, I am turning to SO with my specific use case. I am currently working on a Bootstrap Vue layout where I need to load dates into 12 buttons corresponding to months and display ...

Accessing JSON data from an external file using AngularJS's $http method

I am new to Angular and not very comfortable with JavaScript. I am attempting to create an app using the Ionic framework. I have successfully retrieved a list from a JSON file stored in a variable, but now I am trying to use $http.get() to fetch it from a ...

Verification of Radiobox Groups in AngularJS

Could you please help me with validating a radiogroup using AngularJS, which is instantiated within an additional directive? The validation requirement is that the User must not be able to submit unless one of the radio buttons has been selected. This is ...

Changing the positions of objects on a resized HTML Canvas

I am currently developing a tool that allows users to draw bounding boxes on images using the Canvas and Angular. Everything was working smoothly until I encountered an issue with zooming in on the canvas causing complications when trying to draw bounding ...

The specified property 'length' is not found on type OkPacket within the mysql2 module

In my code example below, I am simply showcasing a specific scenario: this.getCode = (code: string): Promise<codeObject | false> => { return new Promise((resolve, reject) => { pool.query('SELECT * FROM ?? WHERE code = ...

Constantly monitoring the current window width

Is there a way to dynamically get the width of the browser as it is resized in real time? I have found a solution that provides the width, but it only updates when I refresh the page. How can I continuously update the value while resizing the browser? Thi ...

Performing a validation on data fetched using a .load() function

I've been struggling with a persistent issue that I just can't seem to solve. So, here's the situation: I have a blog post on a CMS that I'm developing. The content is saved within a div with its own unique ID. When the user clicks an ...

What could be the reason for parent props not updating in child components in VueJS?

Hello, I am new to VueJS and encountering an issue. In the main.js file, I am passing the user variable to App.vue using props. Initially, its value is {} The getLoginStatus() method in main.js monitors the firebase authentication status, and when a user ...

What is the best way to create a dynamic JavaScript counter, like one that counts the world's population

Can someone guide me on creating a real-time JavaScript count-up feature that doesn't reset when the page reloads? Any tips or examples similar to would be much appreciated. Thank you! ...

Why is it considered bad practice to utilize cacheStorage outside of a serviceWorker?

According to the information provided on the https://developer.mozilla.org/en-US/docs/Web/API/CacheStorage page: The CacheStorage interface serves as the storage for Cache objects, maintaining a directory of all named caches accessible to ServiceWorker, ...

Exploring the Battery Manager functionality within AngularJS

I am attempting to connect the battery manager object to an Angular controller, but for some reason the controller object does not update when the promise provided by navigator.getBattery() is complete. Below is the code I have written: (function(){ var a ...

Unpredictable order of replies retrieved using $http.get

I am struggling to create a function that sends multiple requests to the server based on the number of Ids in the idArray. The issue I am encountering is that the data being pushed into the dataArray does not align with the corresponding Ids of the idArr ...