internet explorer - How to detect where JavaScript alert is coming from? - Stack Overflow

I am trying to debug a very plex IE Intranet application. I am getting an alert with a custom message s

I am trying to debug a very plex IE Intranet application. I am getting an alert with a custom message stating that an exception has occurred. I would like to find out more information about this exception as the message is not very helpful.

There is a master page which contains a lot of iFrames (and .htc files if that makes a difference) so I don't think that I can try and hijack window.alert. My last resort will be to try my luck with a file search.

Using IE 8, is there anyway I can detect where this alert is ing from? The ideal solution would be to somehow create a "breakOnAlert" function which inserts a debbuger statement at the correct alert location.

To clarify: The master page contains many iframes and I believe that the error+alert is ing from one of these. Each iframe is an aspx page (sometimes with dynamic html/javascript from the user) and contains inline and external JavaScript. Before posting I did try overriding alert in my page (a child page inside an iframe) but it didn't work. I am assuming that It doesn't work as each iframe has their own window object so they each have their own version of alert. For this to work I would need to find all iframes and override it for each one, something which I think would be very plicated to do. In the IE developer tools I can see a huge amount of script files (inline and external), so it would be very difficult to manually look for the alerts in there.

I am trying to debug a very plex IE Intranet application. I am getting an alert with a custom message stating that an exception has occurred. I would like to find out more information about this exception as the message is not very helpful.

There is a master page which contains a lot of iFrames (and .htc files if that makes a difference) so I don't think that I can try and hijack window.alert. My last resort will be to try my luck with a file search.

Using IE 8, is there anyway I can detect where this alert is ing from? The ideal solution would be to somehow create a "breakOnAlert" function which inserts a debbuger statement at the correct alert location.

To clarify: The master page contains many iframes and I believe that the error+alert is ing from one of these. Each iframe is an aspx page (sometimes with dynamic html/javascript from the user) and contains inline and external JavaScript. Before posting I did try overriding alert in my page (a child page inside an iframe) but it didn't work. I am assuming that It doesn't work as each iframe has their own window object so they each have their own version of alert. For this to work I would need to find all iframes and override it for each one, something which I think would be very plicated to do. In the IE developer tools I can see a huge amount of script files (inline and external), so it would be very difficult to manually look for the alerts in there.

Share Improve this question edited May 23, 2017 at 12:07 CommunityBot 11 silver badge asked Apr 9, 2012 at 8:43 row1row1 5,5883 gold badges48 silver badges73 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 6

Since it's a real chore to do it in all iframes, I'd probably use Fiddler and programatically replace alert( with something like:

(function(n){alert(n);debugger;})(

IE should support the debugger statement, so you'd have a call-stack

This page explains how to do a text-replace in Fiddler

Example Fiddler custom rule to add to OnBeforeResponse:

if (oSession.oResponse.headers.ExistsAndContains("Content-Type", "html"))
{
    oSession.utilDecodeResponse();
    var oBody = System.Text.Encoding.UTF8.GetString(oSession.responseBodyBytes);
    oBody = oBody.replace(/alert\(/gi, "(function(n){alert(n);debugger;})(");
    oSession.utilSetResponseBody(oBody);
}

Ovveride alert function and set a breakpoint inside, then you can watch Stack Trace :)

 function alert(message) {
     var x = 'whatever';
 }


 $(function () {
     alert('test');
 });

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742366963a4430506.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信