Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Breakpoint right before page refresh?

I'm debugging some 3rd-party minified Javascript that somewhere is triggering a browser page refresh. However, I can't figure out what part of the code is causing the refresh.

Is there a way to put a breakpoint in Chrome that will be hit just before a page refresh so I can inspect the call stack to see what caused it?

like image 406
Thomas Johnson Avatar asked Aug 21 '16 14:08

Thomas Johnson


People also ask

How do I refresh a page in dev tools?

Whenever you are working chrome, try this: Press F12 and open the developer tools. On the refresh button, on the top left of the browser window, do a right click.

How do I refresh inspect in Chrome?

Turns out, if you have your Developer Tools open ("inspect element” on a page), there's a hidden right-click menu on the refresh button in Chrome.

How do you run until breakpoint?

Just press c. It will continue execution until the next breakpoint. You can also disable intermediate breakpoints by using disable #breakpointnumber as stated here.


1 Answers

Try this:

  1. Open your Chrome Dev Tools
  2. Navigate to the "Sources" tab
  3. On the right panel, expand "Event Listener Breakpoints"
  4. Expand the "Load" tree
  5. Check the beforeunload and unload options

See if that helps; screenshot below.

Chrome Dev Tools with Suggested Event Listener Breakpoints Checked

Edit: Alternately, if that doesn't work, you can use Chrome to search all loaded scripts for the code that might be responsible. There's apparently a lot of ways to refresh the page with JavaScript but they mostly have a few common strings like "navigator", "location", "reload", "window".

Finally, if there's a link to the same page you are on, it's possible some JS is triggering a click on it-- unlikely, but worth exploring if nothing else has worked thus far...

(Please excuse the formatting as I'm on mobile...)

NOTE: It seems occasionally, for reasons I don't yet fully understand, this solution fails to actually cause the debugger to pause; in this situation, I found that thorn̈'s answer to this question did the trick for me.

like image 141
Alexander Nied Avatar answered Sep 17 '22 13:09

Alexander Nied