How to find out where the alert is raised from?

后端 未结 4 1417
悲&欢浪女
悲&欢浪女 2021-01-30 10:06

I\'m just curious to know
Is there ANY ways in ANY browser to find out where the alert I get is raised from?

I tried it in chrome but there is no call stack availabl

4条回答
  •  失恋的感觉
    2021-01-30 10:56

    There is a trace function is console is provided by all major browsers. console.trace();

    With Proxy approach, as described in earlier answers, and console.trace(), we can print the entire stack with line number in console itself.

    (function(proxied) {
      window.alert = function() {
    	console.trace();
        return proxied.apply(this, arguments);
      };
    })(window.alert);

    This is an IIFE. Every alert call will have its trace printed in the console.

提交回复
热议问题