Visual Studio Javascript BreakPoint not getting hit, why?

前端 未结 5 1257
终归单人心
终归单人心 2021-02-15 13:05

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

相关标签:
5条回答
  • 2021-02-15 13:51

    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.

    0 讨论(0)
  • 2021-02-15 13:59

    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.

    0 讨论(0)
  • 2021-02-15 14:05

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

    Just enable it and you should be good to go.

    0 讨论(0)
  • 2021-02-15 14:07

    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

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

    0 讨论(0)
  • 2021-02-15 14:09

    Another scenario for the inability of the debugger to stop at the break point is if one uses bundling. To debug JavaScript files, we need to remove bundling.

    I hope this will help someone.

    0 讨论(0)
提交回复
热议问题