Using Chrome JavaScript Debugger / How to break on page loading events

JavascriptDebuggingGoogle Chrome

Javascript Problem Overview


I'm using chrome's debugger and I'm good when it comes to setting break points once a page is running. My problem is when I do either f5 or press enter on the URL line my break points disappear. How can I set a break point in code that happens when the page first loads?

Javascript Solutions


Solution 1 - Javascript

In Chrome's Developer Tools, go to the Sources tab. On the right, open up Event Listener Breakpoints, and you can set breakpoints on events.

It sounds as if you'll want to set your breakpoint on DOMContentLoaded, which is under the DOM Mutation section.

After you do this, reload the page and you'll end up in the debugger.

Solution 2 - Javascript

Try putting debugger; in your code. That also works in FF's Firebug

Solution 3 - Javascript

Later versions of Safari and Firefox should work properly with breakpoints across reloads, but one needs to be sure that the query is exactly the same between requests. ExtJS 4, for instance, adds a _dc=<epoch> that will disable the cache.

To stop that behavior, add the following:

Ext.Loader.setConfig({
    disableCaching: false,
    enabled: true
});

Hope that helps!

Solution 4 - Javascript

I use the next approach that is suitable for Chrome, Safari using Charles Proxy[About] and Rewrite Tool

debugger;

or if you need to make a browser console wait

setTimeout(function(){ 
    debugger; 
    console.log('gets printed only once after timeout');
}, 7000);

setTimeout is a function that will trigger after delay to give a user time to attach the console

Solution 5 - Javascript

Debugger can be set also by using XHR/fetch breakpoint

In chrome developer tools -> sources tab, in the right pane you can see XHR/fetch breakpoint using that you can set breakpoint.

  1. Add breakpoint
  2. Enter the string which you want to break on. DevTools pauses when this string is present anywhere in an XHR's request URL.

If breakpoint has to be set for all XHR or fetch, please check the option Any XHR or fetch

In firefox developer, tools -> debugger tab, adding to the above feature we can set debugger based on request methods.

Solution 6 - Javascript

If you would like to stop the javascript at the time it's first loaded in the browser (and not when the DOMContentLoaded event listener is triggered which happen later) simply click on pause button in chrome debugger and reload your page with F5 keyboard button. It worked for me.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPeter KellnerView Question on Stackoverflow
Solution 1 - JavascriptBennett McElweeView Answer on Stackoverflow
Solution 2 - JavascriptDolan AntenucciView Answer on Stackoverflow
Solution 3 - JavascriptBrian ToppingView Answer on Stackoverflow
Solution 4 - JavascriptyoAlex5View Answer on Stackoverflow
Solution 5 - Javascriptarockia helanView Answer on Stackoverflow
Solution 6 - JavascriptNicolas BourdonView Answer on Stackoverflow