1

I have a bug when EDGE browser crashs in a big project. I need to log all function calls to console to see what function have been called last. And then debug it.

I tried following code, but it shows only calls throught .call() or .apply(), but not if someFunction().

var origApply = Function.prototype.apply;
var origCall = Function.prototype.call;

origApply.apply = origApply;
origCall.apply = origApply;

Function.prototype.toString.apply = origApply;
Array.prototype.slice.apply = origApply;
console.trace.apply = origApply;

function __logCall(t, a, finish) {
  var calledFn = Function.prototype.toString.apply(t, []).substr(0, 100);
  console.log("Calling", calledFn);

}

Function.prototype.call = function () {
  __logCall(this, arguments);
  return origCall.apply(this, arguments);
};

Function.prototype.apply = function () {
  __logCall(this, arguments);
  return origApply.apply(this, arguments);
}

Do you have any ideas?

Ray
  • 129
  • 5
  • how about using console.trace instead? – taile Mar 05 '18 at 16:07
  • add console.log in all functions seems to be the only way – Alex Mar 05 '18 at 16:08
  • 3
    This sounds like an [XY problem](https://meta.stackexchange.com/a/66378/140350). You have a lot of tools at your disposal; logging all function calls is not a very good one. Use Edge's developer tools. Turn on "break on all exceptions" or "break on unhandled exceptions." It will pause when the exception happens and then you can work your way up the call tree, inspecting all of the functions that were called and their arguments. https://learn.microsoft.com/en-us/microsoft-edge/devtools-guide/debugger – Jordan Running Mar 05 '18 at 16:10
  • @JordanRunning, Edge crashes with developer tools without any javascript exceptions. I can stop Edge when it crashing, but no commands from console available. – Ray Mar 06 '18 at 06:01
  • In this case. Did you look up at stack traces with dev tool ? Generally, It will show call stack with the last function that is fired. – Semooze Mar 05 '18 at 16:17
  • Does this answer your question? [Adding console.log to every function automatically](https://stackoverflow.com/questions/5033836/adding-console-log-to-every-function-automatically) – Sergey Mell Apr 28 '21 at 20:29

0 Answers0