By default, the history.state.addObject function is missing. history.state contains the object you clicked (and nothing more).
You can click on what the addObject method addObject , but that doesn't seem like a good idea. If you want the changes to be transferred to the history as a new state, you must explicitly click the state every time in any case. And when you click on a new state, you want to avoid mutating the previous one, which happens if you use the same state object and change it (even if according to the standard , history.state should be a clone of the actual state data). Instead, you should create a new object (it may be a clone of the previous state).
Here is how you can do it.
window.history.pushState( Object.assign({}, window.history.state, {scrollTop: scrollTop}), "RandomTitle", '#' );
It will work even if there is no current state in the history (i.e. window.history.state is undefined ) as Object.assign ignores undefined .
You can also use this function, which automates it:
function extendHistoryState(){ arguments[0] = Object.assign({}, window.history.state, arguments[0]); window.history.pushState.apply(window.history, arguments); }
It works exactly the same as pushState (same arguments), except that it also copies the properties of the previous state in the new state. Therefore, instead of the previous code, you can:
extendHistoryState({scrollTop: scrollTop}, "RandomTitle", '#');