{"id":1233,"date":"2012-04-10T12:00:00","date_gmt":"2012-04-10T12:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/visualstudio\/2012\/04\/10\/javascript-debugging-enhancements\/"},"modified":"2022-10-12T10:10:21","modified_gmt":"2022-10-12T17:10:21","slug":"javascript-debugging-enhancements","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/visualstudio\/javascript-debugging-enhancements\/","title":{"rendered":"JavaScript Debugging Enhancements"},"content":{"rendered":"<p>Visual Studio 11 Beta introduces a first class JavaScript development experience and provides a rich toolset for developing Windows Metro style apps. Debugging is a crucial part of that toolset. In this post I am going to focus on just some of the new scenarios and enhancements we\u2019ve added to JavaScript debugging experience for this release.<\/p>\n<h2>First chance exceptions<\/h2>\n<p>In previous versions of Visual Studio you could only break on unhandled exceptions when debugging JavaScript code. Now, for a given exception type, there is an option to break on exception whenever it is thrown. This is done by enabling the corresponding checkbox under <b>Thrown<\/b> column in the Exceptions dialog (accessible through Debug -&gt; Exceptions menu command). The other column, \u201cUser-Unhandled\u201d, does not apply to JavaScript debugging and is therefore disabled (it applies only to CLR exceptions and is used during managed debugging with \u201cJust My Code\u201d on).\n<a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2012\/04\/4331.image_thumb_6BA57CB5.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-222255\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2012\/04\/4331.image_thumb_6BA57CB5.png\" alt=\"image\" width=\"628\" height=\"311\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2012\/04\/4331.image_thumb_6BA57CB5.png 628w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2012\/04\/4331.image_thumb_6BA57CB5-300x149.png 300w\" sizes=\"(max-width: 628px) 100vw, 628px\" \/><\/a><\/p>\n<p>The default settings enable first chance exceptions for certain error types (for example: Object doesn&#8217;t support this property or method). When the whole <b>JavaScript Runtime Exceptions<\/b> category is checked under Thrown, debugger will break on all runtime errors even if they are not listed in the dialog.<\/p>\n<p>First chance exceptions is an important tool when debugging Windows Metro style apps with asynchronous code that uses promises. An exception thrown in a function passed to the <b>then<\/b> method in a promise is normally \u201cswallowed\u201d by the promise and may not be seen by the developer, especially if there is no error handler passed to the promise chain. With first chance exceptions on, this will now be caught by the debugger and you will break at the throwing statement:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2012\/04\/8561.image_thumb_04351A06.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-222256\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2012\/04\/8561.image_thumb_04351A06.png\" alt=\"image\" width=\"597\" height=\"312\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2012\/04\/8561.image_thumb_04351A06.png 597w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2012\/04\/8561.image_thumb_04351A06-300x157.png 300w\" sizes=\"(max-width: 597px) 100vw, 597px\" \/><\/a><\/p>\n<p>In the example above the element ID is misspelled so document.getElementById returns null which results in an \u201cObject expected\u201d exception for which first chance is enabled by default. You can disable first chance exceptions for that particular error type right from the exception thrown dialog by unchecking the checkbox that says \u201cBreak when this exception type is thrown\u201d. That way debugger won\u2019t break next time when that exception type is thrown. The Debug Output window will still contain the information about all thrown exceptions:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2012\/04\/3386.clip_image002_thumb_18BA6984.jpg\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-222257\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2012\/04\/3386.clip_image002_thumb_18BA6984.jpg\" alt=\"clip_image002\" width=\"628\" height=\"124\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2012\/04\/3386.clip_image002_thumb_18BA6984.jpg 628w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2012\/04\/3386.clip_image002_thumb_18BA6984-300x59.jpg 300w\" sizes=\"(max-width: 628px) 100vw, 628px\" \/><\/a><\/p>\n<p>When breaking on an exception, the Locals window shows the thrown exception object as <b>{exception}<\/b> which you can expand to see its properties. The <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/windows\/apps\/hc53e755(v=vs.94).aspx\"><b>number<\/b> property<\/a> is what defines the exception type in the debugger exception settings.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2012\/04\/2604.clip_image0025_thumb_51651391.jpg\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-222262\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2012\/04\/2604.clip_image0025_thumb_51651391.jpg\" alt=\"exception settings\" width=\"627\" height=\"231\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2012\/04\/2604.clip_image0025_thumb_51651391.jpg 627w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2012\/04\/2604.clip_image0025_thumb_51651391-300x111.jpg 300w\" sizes=\"(max-width: 627px) 100vw, 627px\" \/><\/a><\/p>\n<h2>Debugging web workers<\/h2>\n<p>JavaScript Metro style apps and web apps running in IE10 can use <a href=\"https:\/\/learn.microsoft.com\/en-us\/archive\/blogs\/ie\/\">web workers<\/a> for running JavaScript code in the background. Visual Studio 11 Beta has complete debugging support for web workers. When breaking in the Page context or a worker context, other contexts also stop running. The current context where a break event occurred is shown in the Debug Location toolbar. Page context is shown as the Main Thread whereas a worker context shows the URI of its source document in the thread name.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2012\/04\/7077.clip_image004_thumb_0A0FBD9F.jpg\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-222263\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2012\/04\/7077.clip_image004_thumb_0A0FBD9F.jpg\" alt=\"clip image 004\" width=\"628\" height=\"206\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2012\/04\/7077.clip_image004_thumb_0A0FBD9F.jpg 628w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2012\/04\/7077.clip_image004_thumb_0A0FBD9F-300x98.jpg 300w\" sizes=\"(max-width: 628px) 100vw, 628px\" \/><\/a><\/p>\n<p>Switching to a different context while in break mode is not possible: other contexts are suspended but their location is undefined. You can break in a different context by stepping or hitting a breakpoint or exception there.<\/p>\n<h2>Other enhancements<\/h2>\n<ul>\n<li>Stepping through code during JavaScript debugging shows a significant performance improvement compared to Visual Studio 2010.<\/li>\n<li>Remote JavaScript debugging is now supported (both on x86\/amd64 and ARM remote devices): you can launch JavaScript Metro style apps on a remote device or attach to remote processes running JavaScript code.<\/li>\n<li>DOM Explorer and JavaScript Console are two new tool windows, similar to those found in Internet Explorer\u2019s F12 Developer Tools, accessible through Debug -&gt; Windows menu. These windows allow you to work with a running app and try out modifications to styles, the DOM, or code against the running app through the console. In addition, you could make use of the JavaScript APIs for console.log, to record specific events to the console, as you debug.<\/li>\n<li>The Call Stack window includes more information such as the line and source file information, giving you more context as you debug without the need of frequently switching to other frames.<a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2012\/04\/4846.clip_image001_thumb_3EB019DA.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-222259\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2012\/04\/4846.clip_image001_thumb_3EB019DA.png\" alt=\"clip 1\" width=\"437\" height=\"165\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2012\/04\/4846.clip_image001_thumb_3EB019DA.png 437w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2012\/04\/4846.clip_image001_thumb_3EB019DA-300x113.png 300w\" sizes=\"(max-width: 437px) 100vw, 437px\" \/><\/a><\/li>\n<\/ul>\n<h2>Summary<\/h2>\n<p>These are some of the enhancements of JavaScript debugging experience we\u2019ve added with Visual Studio 11 Beta as part of vast improvement in tooling support for JavaScript. As always, we want to hear your feedback. Please report issues through the <a href=\"http:\/\/connect.microsoft.com\/visualstudio\">Visual Studio Connect<\/a> site. You can add new suggestions for further improvements to <a href=\"http:\/\/visualstudio.uservoice.com\/forums\/121579-visual-studio\/category\/35066-ide\">UserVoice<\/a> or vote on existing ones.<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2012\/04\/8154.clip_image0027_thumb_24037DC1.jpg\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-222260\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2012\/04\/8154.clip_image0027_thumb_24037DC1.jpg\" alt=\"dmitri leonov\" width=\"99\" height=\"158\" \/><\/a>\n<b>Dmitri Leonov<\/b> \u2013 Software Development Engineer in Test, Visual Studio Ultimate team.<\/p>\n<p><b>Short Bio:<\/b> Dmitri Leonov joined the Visual Studio team in 2008. He has been working on the Debugger team since then, where he is now focusing on JavaScript debugging experiences.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Visual Studio 11 Beta introduces a first class JavaScript development experience and provides a rich toolset for developing Windows Metro style apps. Debugging is a crucial part of that toolset. In this post I am going to focus on just some of the new scenarios and enhancements we\u2019ve added to JavaScript debugging experience for this [&hellip;]<\/p>\n","protected":false},"author":13,"featured_media":255385,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[4980,155,1029],"tags":[9,376,124],"class_list":["post-1233","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","category-visual-studio","category-web","tag-debug","tag-java","tag-javascript"],"acf":[],"blog_post_summary":"<p>Visual Studio 11 Beta introduces a first class JavaScript development experience and provides a rich toolset for developing Windows Metro style apps. Debugging is a crucial part of that toolset. In this post I am going to focus on just some of the new scenarios and enhancements we\u2019ve added to JavaScript debugging experience for this [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/1233","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/comments?post=1233"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/1233\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media\/255385"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media?parent=1233"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/categories?post=1233"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/tags?post=1233"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}