3

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,810
  • 10
  • 57
  • 78

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
  • 23,524
  • 7
  • 119
  • 253