Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Javascript BreakPoint not getting hit, why?

Possible to set a breakpoint for the code block of javascript like the screenshot below. How can we use them? VS always ignores.

enter image description here

like image 345
Jude Avatar asked May 06 '14 20:05

Jude


4 Answers

In Visual Studio 2017 there is an option to enable/disable script debugging

Just enable it and you should be good to go.

enter image description here

like image 100
Pierre Avatar answered Oct 24 '22 23:10

Pierre


Yes you can put the break-point on client side page in Visual studio

First Put the debugger in java-script code and run the page in browser

debugger

Add debugger in java-script code

After that open your page in browser and view the inspect element you see the following view

Client side view of break point in java-script

like image 22
Kamran Avatar answered Oct 24 '22 22:10

Kamran


If Internet Explorer is set as the browser when debugging, Visual Studio is, in theory, able to stop at breakpoints set at client side script. To use the feature, you will need to make sure that "Disable script debugging" is checked in your IE Internet Options, Advanced tab.

However, I have found VS script debugging to be a bit flaky; the breakpoint is not always hit, especially with VS2010 or earlier. My personal experience is that it works best in VS2012 or later.

That being said, if you're using VS as the client-side script debugger and you find that your client-side breakpoints are not getting hit, it is best to insert a "debugger;" line prior to the line you would like to break at to ensure that it is picked up by the VS script debugger.

pennstatephil posted a link above that indeed provides more information on the subject: http://msdn.microsoft.com/en-us/library/7seh8d72.aspx

Edit: I'm not able to add comments, but in response to sb9's comment about why one would use IE, I find debugging in Visual Studio a lot more convenient when investigating script behavior before postbacks occur and server-side behaviors occurring immediately after postbacks. Also, sometimes the VS/IE combination will catch errors that Chrome and Firefox/Firebug reports with a nonsensical error message.

like image 39
thesentiment Avatar answered Oct 24 '22 22:10

thesentiment


There are seemingly infinite possibilities to why this happens. I just solved this problem after hours of searching.

My particular issue is that my breakpoints were disabled immediately after my coworker enabled bundling (see description here). I had to go into our BundleConfig.cs file and comment out the line that said:

BundleTable.EnableOptimizations = true;

After I did that, they were hit. You'd want to add that line back in for deployments.

like image 41
sup bro Avatar answered Oct 24 '22 22:10

sup bro