Detect if the Debugger is attached via JavaScript in a Windows Store app

There are some cases where we want a block of o code or function to be executed only when we are debugging the application, usually to show detailed error messages that are intended only for the developer to see.

To be able to detect if the debugger is active during the execution of the application, we can access the Debug object and check the property debuggerEnabled, which will have the value true when the debugger is active:

if (Debug.debuggerEnabled) {
    // We are debugging the app (eg.: F5)
}
else {
    // We are running the app without debugging (e.g.: CTRL + F5)
};

Note: This property is not visible through the Intellisense, but it exists and is used by the WinJS library in the file base.js.

This entry was posted in JavaScript, Windows 8 and tagged , , , , , . Bookmark the permalink.

One Response to Detect if the Debugger is attached via JavaScript in a Windows Store app

  1. Pingback: Global exception handling in Windows Store JavaScript applications | Caio Proiete (EN)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>