locked
How to debug javascript in Visual Studio

    Question

  • Hi,

    We are trying to develop a Windows 8 native application using JavaScript. We are using jquery to dynamically load the javascripts files, and all the javascript files are stored inside of the app. When I try to debug the javascript, the breakpoint can't hit, saying "The breakpoint will not currently be hit....", but in the Solution Explorer, there is a Script Documents project, there is a file called "script block", which contains all the javascripts which are loaded from jqeury. I can debug from there after I disable the "Enable Just My Code", but it's difficult to find the right place to put breakpoint, since this file is huge... 

    Actually all the javascript files are having sourcemap attribute, for example: //# sourceURL=ms-appx://d664ef20-6ac8-11e4-ab78-2f4dc8b50d53/www/resources

    It is working fine with all the browsers, IE, Safari, Firefox and Chrome. But Visual Studio seems not be able to recognize them. 

    Anyone who has the same issue? 

    Regards,
    Xiaojun
    Friday, November 14, 2014 9:33 PM

Answers

  • At development stage, I'd suggest you use static referencing approach so as to make the debugging and testing work conveniently. While for production publishment, you can switch it to your dynamic loading approach if you want.

    For the second question, you're right that the windows store app's javascript eror behavior is different from web browser (which will just stop execution and show error in console). Any exception/error occured in your Windows store app's js code will cause app to terminate if you haven't explicitly catch the error in code. So far I haven't found any global error handler on this.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by xjlight Tuesday, November 18, 2014 4:53 PM
    Tuesday, November 18, 2014 9:31 AM
    Moderator

All replies

  • Hi Xiaojun,

    Are you developing Windows Store app via javascript? If so, how do you load the dynamic script in your store app's code (via jquery)? For Windows Store app with javascript, although it provides web browser like script + html execution mode, there are many additional restrictions which make windows store app's javascript development different from pure HTML + javascript based web page development. And dynamic script execution is somewhat restricted in windows store app's code and it provides specific function for us to execute some dynamic script code at runtime. And normally, store app expect developer to put all script code at dev time together with the app's other page assets (like htm file, images ,etc...) so that they can be packaged into the deployment package and submit for store certification review.

    #execUnsafeLocalFunction method
    http://msdn.microsoft.com/en-us/library/windows/apps/Hh767331.aspx

    And for script debugging, suppose all statically referenced script can be debugged and step through via VS IDE ( see following reference):

    #QuickStart: Debug JavaScript using the console
    http://msdn.microsoft.com/en-us/library/windows/apps/dn688631.aspx

    For your case, if you load those script programmtically (and execute fine at runtime), you can consider change the script to be statically referenced at development time so that you can use VS IDE to debug them as other standard Windows


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, November 17, 2014 7:55 AM
    Moderator
  • Hi Steven,

    Thanks for your support here. We do put all the script files in the package, and use window. eval method to execute javascript codes which are needed at runtime. 

    As you are saying, if we can't reference these scripts in static way, then there is no way to debug? The only way is to put "debugger" statement in script file? 

    Another thing I found interesting is, if there is any error raised by javascript, the application will crash which is different from browser. Is there any way to catch these errors in a global way to avoid the crash? 

    Regards,

    Xiaojun

    Monday, November 17, 2014 7:37 PM
  • At development stage, I'd suggest you use static referencing approach so as to make the debugging and testing work conveniently. While for production publishment, you can switch it to your dynamic loading approach if you want.

    For the second question, you're right that the windows store app's javascript eror behavior is different from web browser (which will just stop execution and show error in console). Any exception/error occured in your Windows store app's js code will cause app to terminate if you haven't explicitly catch the error in code. So far I haven't found any global error handler on this.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by xjlight Tuesday, November 18, 2014 4:53 PM
    Tuesday, November 18, 2014 9:31 AM
    Moderator
  • Hi  Steven,

    Thanks for you support. We will try to follow the suggestion. 

    Thanks,

    Xiaojun

    Tuesday, November 18, 2014 8:13 PM