Debugging Client Script

See Also

You can debug client script in any of these ways:

Note   To debug client script in Internet Explorer, you must be using Internet Explorer 4.0. Debugging must also be enabled in Internet Explorer (this is the default).

It is also highly recommended that you do not use Active Desktop™ mode of Internet Explorer when you are debugging, or set the option in Internet Explorer to launch each new instance of the browser in a new process.

If a Web page contains a mixture of client and server script, you can use the Visual InterDev debugger to debug both. For details, see Debugging Mixed Client and Server Script.

Enabling Client Script Debugging for ASP Pages

Before you can debug client script in ASP pages, you must enable debugging. You can manually enable debugging for your ASP application as described under "Enabling ASP Debugging on the Server" in the Troubleshooting topic. Alternatively, Visual InterDev can automatically enable debugging on the server as needed.

Note   If you intend to work exclusively with client script in .htm files, you do not need to enable server debugging or perform the following procedure.

To automatically enable client script debugging in ASP pages

  1. In the Project Explorer, right-click the project and choose Properties to display the Property Pages dialog box.

  2. Choose the Launch tab.

  3. Under Server script, make sure that Automatically enable ASP client-side debugging on launch is checked.

Note   To debug script in ASP pages, you must be running version 4.0 or later of Microsoft® Internet Information Server (IIS).

When this option is set, each time you start a debugging session Visual InterDev checks that the server is configured for debugging. This includes:

When you quit your debugging session, Visual InterDev restores the server debugging settings and out-of-process setting to their previous values.

Debugging Client Script Within a Solution

If you are working in a Visual InterDev solution, you can debug a file by launching the debugger.

To debug a script from within a solution

  1. In Visual InterDev, open the project containing the page you want to debug and load the page into the editor.

  2. Make the page your project's start page. In the Project Explorer, right-click the page and choose Set as Start Page.

  3. Set a breakpoint in the script to debug. For details, see Setting Breakpoints.

  4. From the Debug menu, choose Start.

  5. If debugging for client script in ASP pages has not been enabled as described above, Visual InterDev displays a message. Your options are:
  6. If client debugging in ASP pages is enabled, and if this is the first time you have launched a debugging session since opening the project, you are prompted to provide user information that identifies the debugging process on the server. (You are prompted even if you are currently working with an .htm file, in case you navigate to an ASP page.) Enter your domain and name in the form domain\name and your password.

    Note   You might experience a delay the first time you launch a debugging session for the current project while Visual InterDev establishes the proper debugging configuration on the server.

    Visual InterDev launches Internet Explorer and loads the page into it. When Internet Explorer reaches the breakpoint, it stops and displays the source code in the editor window. If the breakpoint is in an event handler script, you must trigger the event to reach the breakpoint.

  7. If you find an error, fix it, and then save the file. If you do not have a working copy of the file, right-click the name of the file in the Project Explorer and choose Get Latest Version before you make modifications.

  8. From the Debug menu, choose Restart.

Debugging Client Script in a Running Document

If a client script is already running in Internet Explorer and you detect a problem, you can stop the script and debug it on the spot. You can debug a running document from within Visual InterDev or from within Internet Explorer.

Note   If you are working with an ASP page, debugging must be enabled on the server. For details, see "Enabling ASP Debugging on the Server" in the Troubleshooting topic.

You can attach to a running document only if attaching is enabled.

To enable just-in-time debugging

  1. From the Tools menu, choose Options.

  2. In the Options dialog box, choose Debugger.

  3. Under Script, check Attach to programs running on this machine.

You can attach to a document directly in Visual InterDev.

To debug a running document in Visual InterDev

If Visual InterDev is not already running, you can launch the debugger from Internet Explorer.

To debug a running document from Internet Explorer

  1. In Internet Explorer, choose Script Debugger from the View menu, and then choose Break at Next Statement. In the browser, trigger the event that calls the script you want to debug.

    –or–

    In Internet Explorer, choose Script Debugger from the View menu, and then choose Open.

  2. A new instance of Visual InterDev is launched and you are prompted to open a project. If Visual InterDev is already running, a second instance is launched.

  3. Open the project containing the file to debug. If the project is already open in another instance of Visual InterDev, you cannot open it again, so Visual InterDev creates a new solution and project instead.

  4. The page to debug is loaded into the editor. If necessary, get a working copy of the page. If the project was already open, the page is loaded as read-only file in the new project.

If you make changes to the file, save it and re-deploy it to the server. Refresh the file in Internet Explorer before running the script again.

Debugging Client Script in Response to an Error or Debugger Statement

If Internet Explorer encounters a syntax or run-time error, you can use just-in-time debugging to find and fix it. You can also include a statement in your script, such as a Stop statement in Visual Basic®, Scripting Edition (VBScript) or a debugger statement in JScript™, to launch the debugger from within a script.

You can launch the debugger in response to an error or debugger statement only if just-in-time debugging is enabled.

To enable just-in-time debugging

  1. From the Tools menu, choose Options.

  2. In the Options dialog box, choose Debugger.

  3. Under Script, check Just-In-Time debugging.

To debug in response to an error or debugger statement

  1. When Internet Explorer encounters an error or a statement that starts the debugger, it displays an error message prompting you to debug. Choose Yes.

  2. A new instance of Visual InterDev is launched. If Visual InterDev is already running, a second instance is launched.

  3. Open the project containing the file to debug. If the project is already open in another instance of Visual InterDev, you cannot open it again, so Visual InterDev creates a new project instead.

    The page to debug is loaded into the editor. If necessary, get a working copy of the page. If the project was already open, the page is loaded as a read-only file in the new project.

    Note   If you are debugging a client script generated by an .asp file, the line numbers reported in error messages refer to lines in the HTML document currently displayed in the browser. These usually do not correspond to line numbers in the original .asp file, because server script does not appear in the HTML output of an .asp file. For more information, see Debugging Mixed Client and Server Script.

If you make changes to the file, save it and re-deploy it to the server. Refresh the file in Internet Explorer before running the script again.