Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't the JavaScript debugger pause at debugger statement?

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.)

like image 564
hawkeye Avatar asked Feb 21 '15 09:02

hawkeye


People also ask

What does the JavaScript debugger statement do?

The debugger statement in JavaScript is used for setting a breakpoint in the code. The code stops execution as soon as it encounters the debugger statement and calls the debugger function (if available).

Why is JavaScript so hard to debug?

What makes JavaScript great is also what makes it frustrating to debug. Its asynchronous nature makes it easy to manipulate the DOM in response to user events, but it also makes it difficult to locate problems.


2 Answers

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.

like image 144
Jon Onstott Avatar answered Oct 08 '22 00:10

Jon Onstott


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/

like image 23
Jossef Harush Kadouri Avatar answered Oct 08 '22 00:10

Jossef Harush Kadouri