17

I expect when I insert the JavaScript debugger statement into my JavaScript code that the program will pause at that point and the debugger will open showing the 'breakpoint'.

I'm not seeing this at all.

Here is my code.

<html>
  <script type="text/javascript">
  debugger;
  alert("Hello world!")
  </script>
  <body>
    <p>Hello world</p>
  </body>
</html>

When I run it - I go straight to the 'alert' popup on screen. What is the step I'm missing?

My question is: Why doesn't the JavaScript debugger pause at debugger statement?

(Just to clarify - I had the developer tools open - but at the 'console' tab, not the 'sources' tab.)

4
  • 4
    I think you need open developer tools first. Press F12 Commented Feb 21, 2015 at 9:36
  • In a browser? Developer tools window is open? In IE the debugger is attached? Commented Feb 21, 2015 at 9:36
  • 1
    Some browsers requires the debugger to be opened beforehand. Commented Feb 21, 2015 at 9:37
  • If it doesn't work with the devtools open, try closing and reopening the devtools. I had to do this for some reason (presumably a bug). Commented Jun 7, 2018 at 3:27

3 Answers 3

18

It looks like Chrome won't pause at debugger; statements when the JS code is minified. I don't have source maps set up though.

Sign up to request clarification or add additional context in comments.

5 Comments

THanks that clarified some doubts
I have question: in your minified test code the debugger statement was included? (may be minifier just remove it)
@KamilKiełczewski Can you ask that at the top of the page? (hawkeye has the code, not me)
hawkeye give explicite code on his post without minification (and never mention about it) - but you mention about minification so I ask you - do you check this minification-case?
I don't think it has nothing to do with minimization itself but DevTools – Settings – Ignore List having a regex that accidentally hits the file you're trying to interrupt.
9

You need to open the Developer Tools before the debugger; is executed.

Open using F12 key (read this to learn about more features)


See it in action:

Developer Tools are not opened

enter image description here


Developer Tools are opened

enter image description here

http://jsfiddle.net/qkd5swv9/

Comments

3

The statement debugger; will behave as a JavaScript breakpoint given all of the following are true:

  1. Chrome Developer Tools (DevTools) interface is already open.
  2. The script with the statement debugger is not matched by any of the regular expressions in DevTools – Settings – Ignore List.
  3. The code is not matched by "Custom exclusion rules" in the developer tools Settings – Ignore list.

1 Comment

Thank you for this, you might want to add that there are options above the "Custom exclusion rules:" list too. In my case the ignore list was very long, and the panel prevents scrolling back up. I had to delete a few entries in order to see the top options where I found "Anonymous scripts from eval or console" checked. That was preventing me from using "debugger; window.someFunction();" in the devtools console - wasted a hour trying to figure out why 'debugger;' just stopped working recently.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.