Reputation: 504
I need to debug Javascript from external sources. I found out that you can use either Firefox or Chrome to debug scripts with the internal JS debugger. But the features in these browser developer tools are limited and not the same like in a good IDE. For example I cannot create conditions for breakpoints or setting the command pointer to any other line of code. So my question is how could I use Visual Studio or any other comfortable IDE to do this? I started by opening a new web application in VS and tried to download all the scripts locally. This will work till it comes to special parameters which are not the same like it would run in the real browser e.g. window.location.href
Any advise?
Upvotes: 1
Views: 1192
Reputation: 420
You could add the keyword “debugger” to the line where you want to debug(in JS script files) and then run the Visual Studio in Debug mode by pressing F5.
https://stackoverflow.com/a/29385418/9125096
UPDATE: First, you need enable in JavaScript debugging... in the options of Debug:
Enable JavaScript debugging for ASP.NET
I wrote my JS code just like:
alert(1)
debugger;
alert(2)
and put it in html file as an external source: HTML FILE
Then I press F5, it shows me the first alert: enter image description here
I clicked OK, it stopped at the debugger location in Temp.js file: enter image description here
Upvotes: 1
Reputation: 3776
Visual Studio Code with Debugger for Chrome extension can help you debug Javascript in Visual Studio Code IDE.
Please install Visual Studio code and install Debugger for Chrome extension based on this document:
https://code.visualstudio.com/docs/editor/extension-gallery#_browse-and-install-extensions
Now you can open your project and start debugging your project. After launch in Chrome, you could add breakpoint through Debug menu -> New Breakpoint to choose which type of breakpoint you want to add.
Upvotes: 0