Open BananaHammock743 opened 3 years ago
Saw this prompt when I got up in the middle of the night to check.
Could be related to the website update braking the script, and then because of inactivity in the page it showed up.
I'm seeing this too after about 1.5 hours. This might be a new security feature.
Hi,
Thanks for maintaining this script. This is what I used to detect and avoid auto logouts.
What this does is detect the modal and then clicks on "OK".
const selectors = {
logout: {
dialog: {
window: "#session-expire-time-dialog.dialog-open",
button: ".btn.btn-secondary"
},
}
};
// returns boolean
async function hasLogoutDialog(page) {
return page.evaluate((selectors) => {
const {window} = selectors;
const logoutDialog = document.querySelector(window)
console.log(!!logoutDialog);
return !!logoutDialog;
}, selectors.logout.dialog);
}
Main Function that handles logout dialog
async function handleAutoLogout(page) {
const hasLogout = await hasLogoutDialog(page);
if (!hasLogout) {
return;
}
console.log("Found logout dialog.");
const redirectUrl = await page.url();
console.log("Handling logout.");
await page.evaluate((selectors) => {
setInterval(handleAutoLogout, 1000);
function handleAutoLogout() {
const {window, button} = selectors;
const logoutDialog = document.querySelector(window);
if (logoutDialog) {
document.querySelector(`${window} ${button}`).click();
}
}
}, selectors.logout.dialog);
await page.waitForNavigation({waitUntil: ["networkidle0", "domcontentloaded"], timeout: 0})
console.log("Redirecting to following url: ", redirectUrl);
await page.goto(redirectUrl);
}
And here is the code to trigger auto logout for testing purposes. (Yes! there is a span that is clicked programatically to show the Auto Logout modal on miq's website :| )
document.getElementById("session-expire-time").click()
Usage
await handleAutoLogout();
@nikhil-bhandari Thanks! Are you willing to create a pull request with those changes?
Describe your problem Has anyone else started to be logged out of the MIQ website after X hours (which obviously causes the script to stop running)? Yesterday I came back to my computer and I'd been logged out, with no error message, just the login page showing again.
This morning the same thing happened at approx 5:50pm (NZ time)
I have checked with my partner (the only other person with our login details) and they had not logged in recently which would have caused the expected "single session" logout.
To clarify: I'm not saying this is a miq-nz-booking-tools issue, jut something to be aware of if the MIQ website has started logging users out after X hours. This could also be a local computer issue only I'm experiencing.
Steps yo reproduce
Steps you have taken so far Turned off screensaver completely Turned off screen from turning off after X min Turned off sleep after X min Network adapter settings > Power Management > "Allow the computer to turn off this device to save power" > disabled
Your system (please complete the following information): Win10, using
miq-nz-booking-assistance-Windows-v0.10.2.exe
with Chromium browser