Reputation: 63
I've found that in these versions of Safari and Chrome, pushing a new state value into the browsers history with no user input will behave unexpectedly. It will correctly update the state. You will be able to interact with that updated state using the browser history
API. You will be able to use the MacOS shortcut of cmd + left and right to navigate forward and back in your history.
You will not be able to hit the browser "back" button and have it return to the initial url of the page you loaded. You will see the correct history when long clicking the "back" button. You will be able to call hsitory.back()
correctly.
A simple example snippet:
<!DOCTYPE html>
<html>
<body>
<script>
window.history.pushState({a:1 }, '', window.location.pathname + "?page=1");
</script>
<h1>Safari History Issue</h1>
</body>
</html>
If you load up this html as an index file on a local server you can follow the following steps to reproduce this issue:
pushState()
If you pushState()
as a result of a user action such as an onclick
event this issue is not present.
I am wondering if there is some undocumented security updates in the latest versions of these browsers that is causing this issue?
Upvotes: 2
Views: 519
Reputation: 31
Haven't been able to find any documentation, but it seems like history.pushState calls made BEFORE any user interaction (say click a button) are not "respected".
Upvotes: 2