Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any chance to find source of javascript alert?

I'm working in a large project that was developed for several years and had tons of code. Recently uninformative alert start to appear. It just says Undefined. I need to find the source of this alert. Is the any chance to make something like "breakpoint on alert"? I want to see the source of this alert. One possibility is to redefine alert function. I tried to make it in firefox without any success.

like image 470
IAfanasov Avatar asked Nov 26 '14 11:11

IAfanasov


2 Answers

I'd go with redefining window.alert right at the start of the code for this type of development purposes.

window.alert = function(e){ console.warn( "Alerted: " + e ); }

This will give You a line number for sure. ( Tested on chrome console )

like image 140
István Pálinkás Avatar answered Oct 08 '22 20:10

István Pálinkás


This is an old question, but thought I would help out with a simpler solution. A very easy way in Chrome to find the source is by placing a debug in the console on window.alert:

debug(window.alert)

This will break on alert and take you to the source. In general, using console with debug(fname) will break whenever the function fname is called.

like image 39
nikhilw Avatar answered Oct 08 '22 18:10

nikhilw