Visual Studio Javascript BreakPoint not getting hit, why? - javascript

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

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.

In Visual Studio 2017 there is an option to enable/disable script debugging
Just enable it and you should be good to go.

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.

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.

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

Related

Debug Javascript in Visual Studio 2013 with Just My Code

I enabled Just My Code in Visual Studio 2013 but I cannot hit a breakpoint in my javascript code let alone not stepping into an external javascript library e.g. jQuery. I can hit using debugger keyword and unchecking disabling script debugging from Internet Explorer though. I think MS has introduced such a great feature but it is useless if I cannot use it with ASP.NET.
Someone please suggest anything.
You need to read the documentation in this URL. It tells you all about how VS determines if the code is your code or not, and how to tell VS what is your code and not. Be sure to skip down to the JS section.
http://msdn.microsoft.com/en-us/library/dn457346.aspx#BKMK_JavaScript_Just_My_Code
You can use Firefox and use Firebug plugin to debug your javascript.
Also check Just My Code for JavaScript Windows Store Apps in Visual Studio 2013
The inconsistency of JS breaking in VS is a pain. If I am in a hurry I simply insert an errorable statement (eg., sdfasdf;) at the spot in the JS where I want to look at the variables. This causes an alert window to pop up. Click the 'Break' button and you will be at the line that caused the error. At that point all of your variables will be visible. You can then drag the yellow current line indicator to a line of your choosing and continue processing from there. This has worked for me since VS 2005.

Javascript debugging in VS2010 without using the keyword debugger

I'm using Visual Studio 2010, MVC3, with JQuery.
I've set breakpoints in my javascript functions.
I've checked that my settings are in debug mode.
However, the breakpoints are not being hit. There are many suggestions of using the keywork 'debugger' and making sure that some silverlight option is not checked.
Is there not a way to get debugging to work without using the keyword 'debugger'?
I've gotten it to work on another project a while ago but for the life of me I can't recall how I did it.
Try using firebug instead --> http://getfirebug.com/
Run the web application
In your solution explorer, notice a new item will appear at the top. In my case, localhost appeared.
Double click on the file to open it.
Find the line of javascript you want and set the breakpoint.

Visual Studio 2010 debugging Javascript with IE works but not with firefox or chrome. Any solution?

I have been reading a lot of messages here at stack overflow and googling for some time without any luck. My problem is simple, I want to debug my application from visual studio using firefox or chrome, not IE, but I allways get same error at breakpoint when execute "Breakpoint will not currently be hit. No symbols have been loaded for this document". I have unchecked the disable script debugging in options, have added "debugger;" to the start of my javascript, but allways same error, Could anybody please help?
Thanks in advance,
Mathew.
If you only want to debug Javascript, why not use Firebug in Firefox, and Developer tools in Chrome? These are the best JS debugging tools I ever knew.
My understanding is that you cannot. You'll have to use IE as your browser when you want to use VS as your javascript debugging tool. It's a bit of a pain in vs2010 and earlier as you have to change your default browser that fires up when you start debugging; "Attach to process" from debug menu and "Wait for a request..." under Start Options of the Property Pages don't cut it. Fortunately, the current release candidate of VS2012 have a convenient dropdown that allows you to choose a browser to start debugging with directly on the toolbar. It's a really nice touch and I doubt it will be going away in the RTM version.
As to the exact error you're getting, I've found that happen sometimes when not all libraries are loaded at the beginning of debugging - they're loaded later, on-demand. If you open Debug / Windows / Modules you'll find out what's been loaded, and whether the symbols have been loaded. A quick way around them not being loaded for debug is to instantiate the objects in question early on in the code, so that they're pre-loaded and the debugger knows that you're going to want to be debugging them.
For launching a particular browser: Instead of using the "Start URL" option from the Properties page / Web tab, use "Start External Program." Provide the full path to the browser's .exe of your choice, specify the Command Line Argument as appropriate (e.g., http://localhost/MyApp), and it'll start things off.
As to debugging the JS, though, I'd agree that Firebug is a good tool, and much more helpful than VS's.

JavaScript debugging issue with vs2005

I encountered a strange problem today. Whenever i put a breakpoint in one of my js files, the breakpoint is not hit.
I use Visual Studio 2005 in combination with TFS.
In ie the disable script options are both disabled.
The only thing that changed is that I installed Visual Basic 6 for an old project, but I don't see how that would impact debugging via Visual Studio 2005.
Did anyone had this problem before, or better does anyone know a solution?
thx.
In order for Javascript debugging to work the Visual Studio needs to be attached as a debugger to the IE process and it needs to be able to resolve the phyiscal path of the javascript file with the URL of the same script loaded in IE.
Have you checked that when you start debugging in VS that it actually attaches to the IE process that gets spun up?
Customizer your toolbar, on the commands tab select the debug category then find the "Script Explorer" command, drag it to a tool bar. Close the dialog.
Using script explorer you should be able to find the script that ought to have the break point on. Ordinarily VS is able to combine the root path it specifies for the developer web server with the physical JS file path in order to determine what its URL would look like from the browsers perspective, it can then novate the break point from the physical file to the script loaded in the browser.
you can also use a debugger; statement in your js. IE will then prompt you to debug the script file and should give you the option to debug in Visual studio 2005/2008 if you have them.
Explained here
A collegue found the issue: the Just in time debugger was only set to handle Managed and native code, and no scripting.
I just had to re-set it in the visual studio options pane.

Javascript Debugging in Visual Studio 2008

I'm trying to debug javascript code just by adding a breakpoint in VS2008, but the debugger's not stopping. Do I have to do some special setup in order to enable javascript debugging? Or does the code have to be in a separate js file?
Did you uncheck the checkboxes in the settings
Tools-->Internet Options-->Advanced-->Browsing [heading]-->Uncheck "Disable Script Debugging (Internet Explorer)" and Uncheck "Disable Script Debugging (Other)"
Sometimes you need to restart the browser to get VS2008 to recognize that it has made some changes.
Have you tried to stick the "debugger;" keyword into your JavaScript file? This usually never fails me.
If you have IE8, you can debug right in the browser itself.
Any particular browser? Mainly it works with IE, and needs script debugging enabled in the IE internet options (advanced => browsing).
I don't know about VS2008, but I know I've never been able to get the debugger to stop on a breakpoint in an aspx (as opposed to a linked js file).
If you are not running this in a project, but just debugging on the fly, be sure to attach to the browsers' process.
I know it's not what you asked, but I gotta plug Firebug for JS debugging, including breakpoints, watch statements, stepping, and a live JS console.

Categories

Resources