Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find out where the alert is raised from?

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 available when alert shows.

Any idea?

like image 762
Mo Valipour Avatar asked Oct 18 '11 14:10

Mo Valipour


2 Answers

You can overwrite alert, and create an Error for the stack trace:

var old = alert;  alert = function() {   console.log(new Error().stack);   old.apply(window, arguments); }; 
like image 195
pimvdb Avatar answered Sep 21 '22 07:09

pimvdb


You can monkeypatch the alert to do so:

//put this at the very top of your page: window.alert = function() { throw("alert called") } 
like image 23
Herberth Amaral Avatar answered Sep 23 '22 07:09

Herberth Amaral