Expected behaviour: When i am on a page for x amount of time, once that time expires when i press back on the window i am redirected to a custom page of my choice, in this case google.
My code works however i noticed in the console i am getting a log that says "[Violation] 'setTimeout' handler took XXms"
Why does this happen? Is there another way to write what i am trying to achieve that is more performant perhaps using new Date() ?
let redirect = false;
const ref = setTimeout(() => {
redirect = true;
console.log('history');
}, 5000);
addEventListener('popstate', (event) => {
if (redirect) {
clearTimeout(ref);
event.preventDefault();
window.location.href = "https://www.google.com/"
}
});