Debugging javascript in ASP.NET project - javascript

I'm just starting doing js development, my experience with server-side, XAML, etc. I'm used to intellisence and nice debug experience.
Now I'm struggling. What is the best combo for debugging asp.net with javascript in VS2012? I'm using jQuery. I'd like to have debug breakpoints saved and just edit/start/debug/stop/edit/start... as usual.
Right now when I had VS debugger it would cache js file and it really doesn't work. I have to clear browser cache on every restart. It is real PITA to work like this. F12 tools is not that great either. I have to find js I need and set breakpoints every time I restart application.
People with experience, any help on minimizing pain?

You can use VS2012 to debug the JS by adding the breakpoints as usual then attaching to the IE process after allowing access to debug JS in IE through the settings. That will let you step through the JS as you would code when debugging as normal
Guide (old but still works the same):
http://www.codeproject.com/Articles/18921/Using-Visual-Studio-to-Debug-JavaScript-in-IE

Related

mac os x python/JavaScript IDE where I can use break points

I looking for python/JavaScript IDE where I can put breakpoints. Currently I'm using coderunner but I can not put break points. I'll really appreciate you recommendations
I'm not an expert on Python, but I do work as a web developer and use JavaScript regularly. For that side of things, probably the easiest way is to use Chrome/Firefox debugger tools. You can do this manually by finding the line of code in the console and clicking (F12->Sources tab->Content scripts->desired script), or using the 'debugger' statement to toggle debug mode (F12->Console tab->type 'debugger' then return) and step through to what you need.
Additionally, if you're looking for an actual IDE, the only thing I've found online is the following. Here's the relevant part of that article. I've never used it (and probably never will), but there it is all the same.
Webstorm by IDEA supports setting breakpoints in the IDE. This requires launching the JavaScript debugger from IDEA. It must be configured in advance so it understands how to map JavaScript on the development server to JavaScript files in your environment. IDEA will automatically install a Chrome or Firefox plug-in to facilitate. This is pretty new technology and can be touchy.
I use PyCharm. It's a heavyweight IDE, so expect more features than you probably want if you're just getting started. It has a very good integrated debugger. You'll be able to break into both your Python and Javascript. Further, you'll see a pretty nice productivity jump with all the editing support like auto complete and intellisense. My advice is to stick with print() and logging as long as you can. For me getting a firm grasp of packages, python environments, virtualenv, command line tricks and git all before committing to the PyCharm IDE helped me adopt it with more confidence I was getting the value of all the integration.

How to debug JavaScript code with Netbeans?

I am not experienced in developing web apps with NetBeans.
I created an HTML5 project with existing sources (some HTML, JS and CSS files), the import seems to be OK, but I didn't manage to debug JavaScript code, because the "Debug project", "Debug file" and "Debug test file" menu items are always disabled.
What have I missed?
PS.: I downloaded a fresh version in November 2013.
HTML5 project is always debugging and running at the same time if you run it in any browser with NetBeans connector (check the browser switcher in toolbar). So once you run project/file, if some breakpoint should be hit, it will be. Therefore debug action is not enabled for HTML5 project, because it is the same as Run action.
Basically it means you can debug JS in Chrome with NetBeans Connector, Embedded browser in IDE, Chrome on Android, Safari on iOS...
I also ran into issues when trying to debug JavaScript in a PHP project. I was using Chrome as my browser and had confirmed that the Netbeans Connector extension was installed and working in Chrome.
I could debug PHP without any issues. I could create a separate HTML5/JavaScript project and debug JavaScript without any problem. However, when I tried to set breakpoints on JavaScript code that was embedded in tags within the PHP file, I would get the little 'broken' breakpoints that everyone else references. When I selected the option to debug project, I could debug the PHP code, but the JavaScript breakpoints were never hit.
The change that I made that finally (for me) caused the JavaScript breakpoints to be hit so I could step through code using the Netbeans debugger was to remove the Javascript from the file containing the PHP/HTML code and place the JavaScript in a separate file that only contained JavaScript via a within the PHP file. Magically, I could debug both JavaScript and PHP within the same debugging session without any extra setup.
Of course, one alternative is to use the debugger within the browser, such as Chrome developer tools, but I really wanted to be able to debug everything from within the same Netbeans environment. Works like a charm now.
Never used the JavaScript debugger myself but you find here a tutorial if it has to be the Netbeans debugger. As an alternative I can recommend the JavaScript debugger from Firebug.
Use the Chrome debugger once the page is loaded in the browser.
When you end up solving cross browser compatibility you'll have to use particular browser console/debugger implementation (which may not be fancy). Before that enjoy in ChromeDevTools or FireBug :)

Debugging ExtJS 4 using console.log()

I am very new to ExtJS and still going through the Docs in Sencha site. I've seen a lot of examples in ExtJS4 using console.log() for debugging. However I couldn't figure out how to deal with console.log().
I am using Aptana Studio 3 for development, and I don't think Aptana can run console.log() (correct me if im wrong). So we need to debug it in Firebug? Then how to incorporate script files like ext-all.js, ext-debug.js into Firebug?
Right, the console.log() output from your scripts goes to the console window of the developer tools of whatever browser you're using (e.g. Firebug for Firefox). The browser developer tool picks up the script files from the same place the browser does; i.e. however you have them loaded into your web page.
I would recommend you to use Google chrome. It has a very good developer tool.
Apart from that for ExtJs, use ext-all-dev.js file instead of ext-all.js or ext-all-debug.js while doing any development. It will be really helpful.
Check this link for more details.
Also you can set breakpoints by simply using the command debugger; in your javascript file.
But to make this work make sure firebug/developer tool is running.
Hope this helps.

Best ways to develop painlessly in Javascript on a local machine

I'm pretty new to workign with Javascript.
In most languages you can run the code quickly locally on your machine. From what I've seen, in JS you generally only use it via the browser, and so I've been uploading my code an viewing its effects in the browser. This has proven very tiresome. Also, if I mak one error, it seems like my JS/JQuery will just do NOTHING, instead of giving me a useful error, message, which is making it painfully slow to code in.
IS there some way to run JS locally to see that it is working as I go? And then only upload it to the web when I'm mostly done? What ways are there for me to do this? What ways aer there for me to unit test the Javascript locally? Say I have some JAML that should render as <p>HI</p>, how do I run this locally in a unit test?
Thanks for the help,
Alex
EDIT:
Thanks for all the great suggestions. I'll have to take a bit of time and go through them to see which ones best help me in my situation.
Since you're using jQuery, I assume that you actually want to manipulate the various elements on your page. So depending on your specific development enviroment, uploading it each time is probably the way to go anyway. If you can set up a dev enviroment on your local machine (not always possible) then go with that.
As an actual answer to your question, I suggest using Chrome's developer tools, it doesn't just have the console, but an element inspector, and a resource tracker (resource tracker is invaluable when working with JSON and AJAX, since invalid json will fail silently)
As far as I know, the firebug plugin for firefox (dont use it myself) has a similar feature set, so if you're more comfortable with that go with it.
Just remember, as a developer, your development (and debuggin) enviroment is just as important as the code that you are writing.
EDIT: Noticed that you mentioned unit testing. There are several unit testing frameworks out there for JS including one that integrates with firebug called FireUnit. Do a quick google search to find more if you want.
You don't need to upload the JS file to a server to test it. Just write an html and declare the js binding
<script
src="js/yourJSFile.js"
type="text/javascript"></script>
Edit the JS file in your favorite editor and then refresh the page to test it.
For unit testing the best option is Selenium. It allows you to record an interaction with the browser and then play it back.
You can use Firebug with Firefox to debug JS, and Google Chrome has a debugger built-in (use the Tools -> Developer Tools menu).
You can run Javascript from the local file on your machine in your browser, so you can skip the uploading step.
Also, I'd recommend using Firefox/Firebug combo for developing Javascript as it will be very handy, especially for the part you mentioned about not seeing what's going wrong with your code.
Even if you upload your javascript it gets downloaded back to you as soon as you visit the webpage that invoques it. Its run client side always. So stick to local and use firebug as the others have said. Google`s developer tool is quite nice too.
In the browser if you open the developer tools, follow the following steps:
1) Navigate to sources
2) Under sources, click snippet and open run.js
3) You can use run.js to write as much code as you want and run it locally only to see if your code is working or not (it will give you output on the console)
4) Also you can get used to some keyboard shortcuts to make it faster for you.
5) For small javascript codes, you can navigate to console and run your code there
If you want to do unit testing with Javascript there are extension of Firebug that can help you with that. I haven't try any of them, so I can't really tell you which one are worth considering, but you can easily find them if you search for the keyword "Firebug unit testing" on Google.
What seems to be comming on top is FireUnit. You can find some information about how it works here.
Consider Spider Monkey, which is a javascript engine separate from a browser. If what you are developing does not involve rendering to a webpage or can be separated from the rendering code (good practice!), then this could be useful.
I prefer Chrome to Firefox and I just found Web Server for Chrome.
It's just a Google App that quickly sets up a web server for you and will be set up anywhere you are logged into Chrome. It only allows file access to your current devices, or if you specify, other devices only on the current LAN.
You just point it to the directory with your index.html file and type http://127.0.0.1:8887 in your browser.
Additionally to the answers given you can use Jasmine for automated testing.
A tutorial that seems to help get started with automated testing on Jasmine is provided by Evan Hahn.
I used it and for me it works like a charm. Especially if test driven development is what you are going for!

What steps do you take with VS 2008 to reduce development time with Javascript?

I am seeking your stories on how you have streamlined your client side development with Visual Studio. In particular, it seems that I need to build my site too often in order for changes to pushed down to IE effectively. What shortcuts or tools like FireBug, etc. do you use for your client side development? Do you avoid Visual Studio for debugging your client side apps all together?
We are developing the application which is building almost everything on javascript side, all the controls, webservice call (thru Ajax enabled javascript), grids and all kind of stuff.
We have created framework which includes ExtJs, and JQuery. It makes life easy to initialize and define all the controls in jQuery and make get data using webservice. We can use only ExtJs, however Jquery reduce the number of lines we need to define and set the controls. And of course its very light weight as javascript files are like <25-20 kb which needs to use this frameworks.
I've used the steps outlined by ScottGu here to get a better JS intellisense for VS 2008.
(As it is pointed out here, this patch is intended for all JavaScript files, not just jQuery.)
I use the vsdoc files to get intellisense working for jQuery.
lately, I had to work in a VS2005 + IE6 only environment. I've quickly got used to having Firefox for debugging with the tools I subjectively deemed essential: Firebug, PageSpeed, FireQuery.
I tried Aptana. (As of yet however, I didn't invest much time in getting to know it - you may find it familiar if you are equipped with some Eclipse knowledge, though...)
After all is well and done, I check pages in IE and use the built-in profiler in IE8 if there is some IE specific perf issue.
I use the "empty vsdoc" workaround when VS intellisense gives up.
At home, I use VS 2010 RC - and at all places I keep the API references of JS frameworks bookmarked and within reach, just in case.
Place Javascript code in separate JS files.
You might want to consider turning your related sets of functionality into a ScriptControl.
When you work on some JS file and want to avoid the time of rebuilding the whole project, do not make it an embedded scriptresource from the start. Package it in the assembly when it is stable enough.
If you are in doubt whether you get the latest version of your JS file, disable the browser cache. (It can be done from FireBug, or in the IE dev tools.)
Disclaimer: this list is really subjective and probably not complete at all.

Categories

Resources