4

I know its easy to intercept a function in js, among other ways:

console.log = (function () {
var log = console.log;

return function () {
    alert(arguments);
    log.apply(console, arguments);
})();

but Is there a way to wrap console.log such that when a user calls

console.log("hi")//in random.js

in the console it shows the random.js origin, and not the location of the intercept?

maxfridbe
  • 5,872
  • 10
  • 58
  • 80

1 Answers1

0

Use a try/catch rather than returning a function:

console.log = Function("a", "try { console.info(a); } catch(e){return e}");
Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265