debug JS code which triggers an alert()

后端 未结 3 732
心在旅途
心在旅途 2021-02-07 23:18

I have a system which is built using the ext-js library. Part of the system lists orders that are flowing through an online store. When a row is clicked, additional order detail

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-07 23:53

    Firebug has a command line API to programmatically create breakpoints. For example:

    debug(fn);
    

    creates a breakpoint to the function fn. Unfortunately this can't be used for functions with native code (built-in functions like alert). However, you can use this trick.

    Insert a script block in your code with this script-

    window.alert_ = window.alert;
    window.alert = function() {
        alert_.apply(window,arguments)
    };
    

    What you've done is to redefine window.alert with your own which does the same thing.

    Now attach the breakpoint in firebug with:

    debug(alert);
    

    Now the next time a script calls alert, you will get a breakpoint in your function. You can then analyze the stack trace and find out where it is getting called from.

提交回复
热议问题