Javascript debugging in VS2010 without using the keyword debugger - javascript

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.

Related

Javascript breakpoint not work in Visual Studio 2019 asp.net application

I recently upgraded from VS 2017 to VS 2019.
In VS 2017, when running an asp.net application locally, using Chrome, I could put a breakpoint in javascript code and the debugger would stop on the breakpoint. This no longer works in Visual Studio 2019.
What do I need to do to enable javascript debugging in Visual Studio 2019 using Chrome? I would like to be able to put breakpoints in javascript files and have them hit.
Here is my setup.
I've enabled Javascript debugging.
I put a breakpoint in my Javscript code. This breakpoint is in a *.js file (not inside a Razor view).
The breakpoint is ignored. Visual Studio very courteously shows me a tooltip telling me the breakpoint will be ignored.
It should work in VS2019+Chrome.(I just checked this in several machines)
This is not one issue can be resolved directly since many factors can cause this behavior, you can follow suggestions below to check if it helps:
1.Update your VS2019 to latest 16.3.7, update your chrome browser to latest 78.0.3904.87
2.Delete the bin and obj folders in your project directory => then close and restart VS => open that project and do a clean rebuild
3.Make sure you're in debug project mode, right-click your web project=>Set as StartUp project
Also, sometimes we need to wait for several seconds before the debug session starts successfully.(I once met same popup, then after several seconds it disappeared and everything worked)
Hope it helps :)
Besides enabling JavaScript debugging in Visual Studio, please ensure that minification is off. (Turn off bundling/minification while debugging in WebForms)
If your page contains Razor syntax, the breakpoints won't work.
Instead add the debugger; statement into the script as a breakpoint.
Then again, the debugger statement had failed to work earlier this year. It only works at top level, means before the page is completely rendered. It will not work if I put the debugger statement into $(document).ready()
So my work around now is to put my javascript in a separate .js file without any Razor syntax.
The good old console.log works for me as nothing suggested as above answers are working at all. Anyway it is what it is amidst the frustration for VS, nothing new about that.
If your Javascript is in a Razor file it will not work.
I have been struggling with this for ages and getting by with console.log.
But just now I moved the js into an external file and bingo it works.
I am using latest VS 16.11.5 and Chrome in a .Net 5 project with Razor pages.

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

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.

Interactive Javascript console (preferably integrated with Firebug)

I'm looking for a way to have an interactive JIT debugger, preferably integrated with Firebug.
I got the idea from PHPEd, which has an "Immediate" debug tab where you can just type in PHP code and modify objects on the fly. This makes debugging a breeze as you can re-assign variables multiple times, re-execute functions, etc without leaving the program.
Here's what I think would be superb:
- set a breakpoint in Firebug
- arrive to breakpoint
- have an Execute JS tab where one could enter JS code, similar to what I described above
Does anything like this exist already?
TIA.
You can already do this in Firebug. Just get to a break point, then go to the "console" tab, and type your commands into the command line at the bottom (where there's the ">>>").
If I understand the question correctly, I think can do that already in firebug.
Set a breakpoint (or use the debugger
keyword)
Click the console tab
the bottom line allows you to enter a
javascript command.
if you need more space click the icon
that looks like an upside down v in
the bottom right part of the browser.
You might also like the JS execute extension.
Actually, Firebug can do this and it's only a matter of a little investigation on their website to find out how to do this best :) Good luck!
Agree with parents that Firebug is the best choice. Another option that requires a good deal of configuration would be Aptana. For folks using the Eclipse IDE, Aptana is a solid editor for Javascript work. The plus with Aptana is that it's tied more to a code editing environment.

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