Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome javascript debugger breakpoints don't do anything?

I can't seem to figure out the Chrome debugging tool.

I have chrome version 21.0.1180.60 m.

Steps I took:

  1. I pressed ctrl-shift-i to bring up the console.
  2. Clicked on Sources then select the relevant javascript file that I want to debug.
  3. I set breakpoints where I want the code to stop by putting a blue tag on the gutter next to the line on the left.
  4. I clicked on the button on my webpage (which is a php rendered page) that initiates the javascript code.
  5. The code ran successfully without stopping.

I also noticed that the Watch Expressions don't work either. It keeps telling me that the variable that I want to watch is undefined.

Further testing found that it's my code that's causing the breakpoint to fail. It seems that it fails on the "$("#frmVerification").submit(function(){" line. It doesn't step into the breakpoints inside that function().

Below is the:

//function to check name and comment field  var test = "this is a test"; var test2 = "this is another test";  function validateLogin(){     //if(userEmail.attr("value") && userPass.attr("value"))         return true;     //else         //return false; }  //onclick on different buttons, do different things. function ajaxRequest(){  } $(document).ready(function(){   //When form submitted     $("#frmVerification").submit(function(){         var username = $("#username");         var token = $("#token");         var action = $("#action");         var requester = $("#requester");         if(validateLogin()){             $.ajax({             type: "post",             url: "verification.php",             data: "username="+username.html()+"&token="+token.val()+"&action="+action.val()+"&requester="+requester.val(),             success: function(data) {                 try{                     var jsonObj = $.parseJSON(data); //convert data into json object, throws exception if data is not json compatible                     if(jsonObj.length > 0){//if there is any error output all data                         var htmUl = $('<ul></ul>');                         $.each(jsonObj, function(){                             htmUl.append('<li>' + this + '</li>');                         });                         $("#errOut").html(htmUl);                     }else{                         alert("Your account is now activated, thank you. If you have already logged in, press OK to go to the home page. If not, you must log in first.");                         window.location.replace("home.php");                     }                 }                 catch(e){//if error output error to errOut]                     $("#errOut").html("PHP module returned non JSON object: <p>"+data+"</p>");                 }             }         });     }     else alert("Please fill UserName & Password!");         return false;     }); }); 
like image 437
chaser Avatar asked Aug 03 '12 01:08

chaser


People also ask

How do I enable JavaScript debugging in Chrome?

Press the F12 function key in the Chrome browser to launch the JavaScript debugger and then click "Scripts". Choose the JavaScript file on top and place the breakpoint to the debugger for the JavaScript code.

Can you use breakpoints in JavaScript?

In the debugger window, you can set breakpoints in the JavaScript code. At each breakpoint, JavaScript will stop executing, and let you examine JavaScript values. After examining values, you can resume the execution of code (typically with a play button).

How do you hit a breakpoint in JavaScript?

To enable the new multi-target debugger in VS 16.7 or newer please go to Tools -> Options -> Debugging -> General -> and check the option: “Enable using the multi-target JavaScript debugger for debugging JavaScript in ASP.NET projects (requires debugging restart)”


1 Answers

I'm not sure why your breakpoints aren't hitting, but one sure-fire way to step into your code is to type

debugger; 

where you want the code to halt, and then run again with the chrome developer tools window open.


Just one small thing to be aware of, be sure to clean up after you done and remove the debugger lines. If you ever run JavaScript files through YUI compressor, the existence of a debugger; line will cause it to error out.

like image 114
Adam Rackis Avatar answered Oct 06 '22 00:10

Adam Rackis