function wrapState(action) { let raw = history[action]; return function () { let wrapper = raw.apply(this, arguments); let e = new Event(action); e.stateInfo = {...arguments}; window.dispatchEvent(e); return wrapper; } } history.replaceState = wrapState("replaceState");