Triggering a reroute within a scroll event removes current URL from history (Chrome, MacOS)

29 Views Asked by At

The following webpage (let's call it test.html) behaves differently in Safari, Firefox, and Chrome. This question specifically relates to its behavior in Chrome.

<html>
  <body style="height: 200vh">
    <script>
      window.addEventListener('scroll', () => window.location.href = 'https://www.google.com')
    </script>
  </body>
</html>

If I start with an empty tab, go to test.html, scroll and thereby trigger the reroute to google.com, then click the back button, I'm sent to the empty tab page - even though test.html is visible in the history if you click and hold the back button. The forward button skips over it too.

I've tried a few things, including changing the listener to 'wheel', resetting the scroll location using onbeforeunload, and using a boolean flag to make sure the reroute only gets called once.

Any insight into what's happening here? Is this a Chrome bug, or working as intended?

0

There are 0 best solutions below