Skip to content

Instantly share code, notes, and snippets.

@x3388638
Created January 21, 2021 08:16
Show Gist options
  • Save x3388638/91d3b70ccc4d9419155df95b96683844 to your computer and use it in GitHub Desktop.
Save x3388638/91d3b70ccc4d9419155df95b96683844 to your computer and use it in GitHub Desktop.
Log all pushState and replaceState events in console
// ==UserScript==
// @name HistoryLogger
// @namespace 2yc.tw
// @version 0.1
// @description Log all pushState and replaceState events in console
// @author YY
// @match *://*/*
// @grant none
// ==/UserScript==
(function() {
const _pushState = window.history.pushState.bind(window.history);
const _replaceState = window.history.replaceState.bind(window.history);
window.history.pushState = (...args) => {
console.groupCollapsed('[PUSH_STATE]');
console.log(JSON.stringify(args, null, 4));
console.groupCollapsed('trace stack');
console.trace();
console.groupEnd();
console.groupEnd();
_pushState(...args);
};
window.history.replaceState = (...args) => {
console.groupCollapsed('[REPLACE_STATE]');
console.log(JSON.stringify(args, null, 4));
console.groupCollapsed('trace stack');
console.trace();
console.groupEnd();
console.groupEnd();
_replaceState(...args);
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment