Debug a native JavaScript method

tags:  javascript

Write in the Chrome Inspector / Firefox Developer Tools:

debuggingMethod = window.debugginMethod;

window.debuggingMethod = function (...arguments) {
  console.trace(arguments); // console.log
  debuggingMethod.apply(window, arguments);
}
  • Use function better than arrow function to avoid undesired scope changes.

Example

replaceState = window.history.replaceState;

window.history.replaceState = function (...arguments) {
  console.trace(arguments);
  replaceState.apply(window.history, arguments);
}