1

Here is the situation. A popup window contains the javascript I need to debug. It also contains a re-direct that happens so fast I can't open the Inspector fast enough to have the breakpoints fire. I start with the Inspector open and click a link which closes the Inspector and opens the popup window which contains the javascript. But the logic happens and the re-direct fires so fast I can't open the Inspector before Chrome is already off the popup with the script I need to debug.

I've read the Google documentation and setting breakpoints works great but the breakpoints only fire if the Inspector is open.

I tried using debugger; which I found from this SA answer but once again, it only fires if the Inspector is open.

Just to debug it, I also tried setting a "sleep" function (which chews up processor, is bad etc) like this:

function sleep(milliSeconds){
var startTime = new Date().getTime(); // get the current time
while (new Date().getTime() < startTime + milliSeconds); // hog cpu
}

sleep(5000);

That didn't work either.

Is there a way to get the Inspector to pop open via code? If not, what is the best way to debug this? Thanks.

Community
  • 1
  • 1
Joshua Dance
  • 8,847
  • 4
  • 67
  • 72

1 Answers1

1

I've been struggling with this issue all day and finally hit upon a solution. Simply place an alert in your code before the debugger statenent:

alert('Time to attach the debugger');
debugger;

When the alert appears on the screen, simply click the "inspect" link in Chrome Inspector. The inspector will attach to your page and you can then click OK on the alert box to continue. It will then stop at the debugger statement

Kesty
  • 610
  • 9
  • 19