Debugging JavaScript / VBScript script (ie)


Both of these methods can be debugged by using visual studio. First, you can see the debugging of Web script programs that are frequently used:
1. To debug the script program in the web page, the debugger needs the host program – here is ie support. In fact, all script program interpreters implement a com debugging interface. The debugger can set breakpoints, query variables and catch exceptions by querying this interface of the interpreter. Of course, to query this interface, the host program needs to agree As for how to implement this interface, we will talk about it in a later article.
2. By default, ie turns off script debugging support, so you need to turn it on explicitly. Open IE, click “tools” – Internet Options, select the Advanced tab in “Internet Options”, and in the “Settings” list, find the “disable script debugging (Internet Explorer)” option, which is checked by default – tick it off.

3. Use IE to open a new web page, whether it is a remote web page or a local web page (opened from the local hard disk). For example, the following page is saved as test.html:

Copy codeThe code is as follows:
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN””>
<html xmlns=””>
< title > JavaScript debugging < / Title >
<script language=javascript>
function onload() {
var test = unescape(“”);
<body onload=”onload()”>

4. Start visual studio, click Tools – attach to process menu in vs menu to open the attach to process window. Visual studio actually supports many debugging modes, such as debugging C + + (native) programs, debugging. Net (managed) programs, debugging script programs, debugging Silverlight programs, and debugging SQL stored procedures. By default, visual studio selects the most appropriate debugging mode based on the additional process type, but sometimes you need to set it manually. For example, Internet Explorer can run multiple subprograms at the same time, ie itself and ActiveX control are written by C + + / C, ie can run WinForm / WPF program, ie can run Silverlight program, of course, the most common one is running JavaScript / VB script program. Visual studio is always confused by ie when it is attached to the Internet Explorer process, so we need to manually tell visual studio what debugging mode we want to adopt.
In the attach to process window, in attach to (attach to…) Click the “select” button next to the text box. In the pop-up “select code type” window, check “debug the following types” and select “script”. As shown in the figure below:
Debugging JavaScript / VBScript script (ie)
5. Then you need to select the process to attach in the “attach to process” window. In the “available processes” list, there is a “type” column, which lists the debugging modes supported by the corresponding process. For example, in the figure above, several iexplore.exe supports scripts and C + + debugging modes (script, x86). So all you need to do is find the process to execute the web page. Here I choose iexplore.exe with ID 3732, because that is the process to run the third step of the web page. Finally, click the attach button to debug the specified IE process using script debugging mode.
Note: careful netizens may see that the title of iexplore.exe with ID 1692 is “JavaScript debugging” – corresponding to the browser process ID of the webpage we execute. In fact, before IE 8, the browser process of selecting and executing web pages was generally done according to the title of the browser, but there are some changes in IE 8, which will be mentioned in the article after the change.
6. After attaching, set a breakpoint in the seventh line of the web page (the source code of the web page is in the third step) – just like debugging C ා and C + + code, after setting, return to IE process and refresh the web page. At this time, visual studio should interrupt the execution of IE on line 7 of the web page. You can view the value of script variables in the watch window: