how to prevent websites from log you out due to inactivity - javascript

I am working with 5 different websites which have short session life, they log out in 10 - 15 mins of inactivity.
I came up with browser extension to do the jon for me.
and what I did so far:
reloading the page.
open another tab from the same host and close it automatically.
switch tabs to be active automatically ( like every 2 minutes one of thes websites becomes active).
those seems to be working, but they had very bad user experience.
also, reloading the page might cause losses of the work that I am doing.
I tried to make some requests on the background but these websites use alot of headers and cookies which seems to be very hard to figure out how to use them.
is there a better way to stop logging off due to inactivity or a proper way to figure out which headers and cookies should I attach with my request??
I really don't know which stack these websites are using but it seems that they have a high security standards.

What I tend to do is once the "Are you still there?" message pops up, I right click, inspect, copy the selector, then do this in the console:
# paste your selector in this variable
selector = "#j_idt473 > div.modal-footer > a.btn.btn-primary.btn-sm"
document.querySelector(selector).click()
If that works, I then put it in a intervalID = window.setInterval(callback, milliseconds) call. I stop the loop with window.clearInterval(intervalID) if needed.
Not sure if you'd consider a realtime hack, this is StackOverflow after all.

Related

"location.assign(url)" sometimes appears to lead to a wrong URL on mobile, though works fine in most cases

I have a page with a timeout - it must automatically redirect to another, specific URL, say "http://example.com/?x=1", 60 minutes after loading.
So I simply added setTimeout(function() { location.assign('http://example.com/?x=1'); }, 60000); to the page's JavaScript.
Usually this works just fine, but sometimes it ends up at "http://example.com/", losing the 'x' parameter somehow. This probably happens only on mobile browsers. One user reported the same problem on desktop, but it might have been a fluke. I'm guessing that it happens because a mobile browser left idle for an hour may get killed by OS and when I reopen it, it goes to the homepage by default. But why? Isn't it supposed to remember the full URL and get back to it after reactivation? Something doesn't make sense.
Has anyone encountered such a problem or has any idea why this might be happening? This happens on various platforms and browsers.
Yes, I know that I can probably fix this using a cookie or a session-wide variable or something, but I need to understand why this particular problem is happening. Thanks for understanding.
A few things I noticed here. First - you say 60 minutes, but 60000 is only 60 seconds :) On why you'd lose the querystring on setting location ... that's super weird and I have no idea why it would happen. The good news is, maybe you don't need JavaScript for this at all? You can use a meta tag!
<!-- Redirect page after 3 seconds -->
<meta http-equiv="refresh" content="3;url=https://www.mozilla.org">
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta

Prevent Chrome 80 from freezing tab with my page

I have a simple html page that displays some monitoring results, it reloads every 2 minutes and makes noise when those results are not acceptable. I keep this page open 24/7, so new Chrome started freezing and suspending it, as I found out via chrome://discards/ .. So the page stopped making noise and catching my attention, mostly cause the tab gets frozen by Chrome. That happens if I forget to leave the tab with this page active, "on top". Is there a rather simple way to prevent Chrome from freezing the tab, even if it is not active? I could involve some Javascript, if needed..
I am aware that there is a simple solution of opening new window with this page and leaving it alone. On the other hand, I made the page, so I can make changes to HTML in order to ensure that page remains unfrozen. I tried updating title with current time on every reload, this visibly helped, page seemingly always has fresh time in the title, but it still doesn't make noise. And if I switch into it when noise is supposed to happen, - it starts the sound half way like it was trying to all alone.. it's even funny..
Is there any simple solution to this? Thanks for your help.

Autoclick buttons in several tabs

I have about 10+ tabs open in my browser with each containing a button I need to click, in intervals of about 20-30 minutes.
I am looking for some kind of autoclick solution so that I don't have to go back to my browser every 20-30 minutes and manually click the button.
I downloaded an extension for Firefox called Autoclick but this didn't work. I'm thinking if there is maybe a better solution so that I can program these buttons in advance to be clicked in the interval I specify.
I am not sure here what the best solution would be. I'm wondering if anyone would have an idea.
I do not own this domain by the way so altering the source code of the form that needs to be sent is no solution.
You can give Selenium a try. It can be installed as a plugin/extension in your browser.
Selenium for chrome for example can record your actions and then playback them for you automatically.
Not sure about multiple tabs, but it should be possible.

Pause the user exiting a page

Using JavaScript (and/or jQuery), Is it possible to pause the user from exiting a page for a set amount of time without showing an alert/confirmation?
(Say the user clicks on a different page or closes the window, a timer should start for three seconds [during which time something happens] and then the next page is loaded or the window closes.)
No, it is impossible in modern browsers.
(Moreover, think of how annoying that would be if every popup did that)
The closest you can do is show the dialog using onbeforeunload but you have asked to avoid this.
But why would you want to do that?
Worth mentioning, that this is a magical time. You might want to report something to the server but you suddenly can't because the user is leaving. This is one of those times things that are usually considered bad practice like synchronous ajax might make sense.
No. This is not possible. At best you can implement an onbeforeunload handler but your options at this point are very limited (you can certainly not 'wait 3 seconds').
Browsers will try to protect the user so this is behavior that browsers enforce and they have incentive to enforce it.
This works in chrome and firefox:
window.onbeforeunload = function() {
var now = new Date();
while( new Date() - now < 3000 );
};
It will also drain battery, so you are killing 2 birds with one stone.

How can I delay leaving a page via javascript?

I'm trying to get add a delay of 1000ms before a person leaved the page. I'm using the beforeunload event to start a jquery animation and would like it to finish before the page leaves.
I'm not concerned with older browsers, IE9, latest safari, chrome and FF4 are all i'm interested in.
Edit: Well I was hoping to implement it when just navigating internal pages. Sure I can make all my internal links a javascript call, but I would have preferred a less brute force method.
Also, I'm not stopping people from leaving the page, not even making them wait a huge long time, 1 second for a fade out? Thats no worse than every game I play fading out when I select quit.
Now had I asked how do I prevent a person from leaving a page, then yes all the "don't do it" would have been deserved.
Firstly, if people want to leave your page, don't put any barriers or difficulties in leaving it. Just let them.
Konerak said it well...
Using a blocking action is acceptable when the user is about to lose data by leaving the page, but using them for animations and gimmicks will quickly annoy your users.
Secondly, you can only prevent automatic closing with a blocking action, such as an alert() or prompt(), which temporary blocks the browser's viewport, waiting for user response.
jsFiddle.
Well I was hoping to implement it when just navigating internal pages.
I know it’s four years later now, but I wanted to point out that, within the bounds you’ve described, you can do this.
$(document).on("click", "a", function (e) {// Listen for all link click events on the page (assuming other scripts don’t stop them from bubbling all the way up)
// Stop the link from being followed.
e.preventDefault();
// Grab the link element that was clicked
var linkClicked = e.target;
// I'm using setTimeout to just delay things here, but you would do your animation and then call a function like this when it’s done
window.setTimeout(function () {
// Simulate navigation
window.location = linkClicked.href;
}, 1000);
return false;
});
It’s still inadvisable:
I suspect it would get annoying to users pretty quickly
Without additional code, this would prevent users from command/control-clicking to open links in a new tab.
8 years later and I'm about to code this for my own website, specifically as a fade between pages. But I'm only going to do this for navigating between pages within my site, and I'm not going to use window.onbeforeunload or window.onclick. I attach a click event handler to specific "buttons" on each page. pointer-events is even disabled for other elements, so the event's element scope is very limited. The code is a switch() statement with cases for each "button". Each button navigates to a specific page within the site.
I don't think this is bad web page or web site behavior. A 1 second delay when transitioning between pages is not going to annoy users. I think you might be able to get 2 seconds or more out of it, if you include the time it takes to load the destination page, which can also fade in gradually in as it loads data.
It's visually elegant, especially compared to typical news/info sites with flex layouts that shift all over the page while they load. Those pages spend 2 or more seconds shifting stuff around before you can read anything.
My site is already filled with CSS and SVG animations, so adding this to the internal page navigation is no sweat for this project. If you limit the element scope of the user events and you make the delays small, this is good behavior, not bad behavior, IMO. Visual elegance has value.
EDIT- As I get into it, I see that for one group of similar pages I can achieve better cross-fading between them by consolidating them into one page. That way I can truly cross-fade between each sub-page instead of fading out one page then fading in another.

Categories

Resources