Skip to content

Instantly share code, notes, and snippets.

@mendes5
Created October 20, 2021 19:43
Show Gist options
  • Select an option

  • Save mendes5/eaad8b70060f1e82a24c2d02c2f6ad4f to your computer and use it in GitHub Desktop.

Select an option

Save mendes5/eaad8b70060f1e82a24c2d02c2f6ad4f to your computer and use it in GitHub Desktop.
Hook into history and location functions to execute the debugger to debug unexpected URL changes
const _pushState = window.history.pushState.bind(window.history);
window.history.pushState = (...args) => {debugger; return _pushState(...args)};
const _replaceState = window.history.replaceState.bind(window.history);
window.history.replaceState = (...args) => {debugger; return _replaceState(...args)};
const _replace = window.location.replace.bind(window.location);
window.location.replace = (...args) => {debugger; return _replace(...args)};
const _reload = window.location.reload.bind(window.location);
window.location.reload = (...args) => {debugger; return _reload(...args)};
// TODO:: hook window.location getters and setters as well
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment