0

I'm adding a new entry to my browser's history stack with pushState. Now popstate event should fire when pressing the back button, right? And at least on mobile, it requires some kind of user action before pressing the back button to fire (scroll or touch).

This is my current situation and it is working nicely on mobile if I click or scroll a bit before pressing the back button.

Now if I add touchstart, touchmove or touchend event listener then popstate event is firing only if I perform touch first and then press the back button. But it is not firing if I scroll only and do not perform touch.

Below are two snippets of code that explain the situation.

Alert is shown, only small scroll is required before pressing back button:

window.addEventListener('popstate', () => {
    alert('This is test');
});

Alert is not shown, requires click before pressing back button:

window.addEventListener('popstate', () => {
    alert('This is test');
});

document.addEventListener('touchmove', () => {
    // Empty eventListener here
});

Any ideas why it is not working with scroll-only after adding touch event listeners?

Purg3ri
  • 1
  • 1
  • Does this answer your question? [Chrome popstate not firing on Back Button if no user interaction](https://stackoverflow.com/questions/57339098/chrome-popstate-not-firing-on-back-button-if-no-user-interaction) – dippas Mar 22 '22 at 18:45
  • Nope, I've tried that before and tried one more time. @dippas – Purg3ri Mar 22 '22 at 18:54

0 Answers0