Debugging scripts
The Scripts panel of the Web Inspector allows you to debug the JavaScript code used by your webpage. By allowing you to set breakpoints and to step through your code, the Web Inspector can help to locate and correct problems within your code. When you determine that the script is functioning as intended, you can copy the changes back into the source file.
To use the Scripts panel, you must first enable debugging. The Web Inspector prompts you to enable debugging when you first view the Scripts panel; you can choose to enable debugging for just the current session, or to always enable debugging.
The Scripts panel
You can click the Scripts icon in the toolbar to display the Scripts panel. If you have not already enabled debugging, the Web Inspector prompts you to do so.
The Scripts panel is divided into two sections. On the left is the document pane, which allows you to view and debug JavaScript. On the right is a set of collapsible panes which display information related to the displayed script.
A toolbar at the top of the Scripts panel allows you to choose the script file you want to inspect and to cycle between open scripts. It also provides a set of controls that allow you to step through the script displayed in the document pane.
Set and use breakpoints
- Click the Scripts icon on the toolbar to display the Scripts panel.
- In the line gutter of the document pane, click the line at which you want to set a breakpoint. A breakpoint marker appears in the line gutter, and the new breakpoint is added to the Breakpoints pane, identified by the script filename and line number. The execution of the script pauses at the specified breakpoint.
-
Perform and of the following actions:
- To continue the execution of the script beyond the current breakpoint, click the Continue button in the Scripts panel toolbar.
- To display the line of code associated with breakpoint in the documents pane, click the breakpoint entry in the Breakpoints pane. The document pane displays and highlights the associated line.
- To disable a single breakpoint without removing it, in the Breakpoints pane, uncheck the break point. The execution of the script no longer pauses at the disabled breakpoint.
- To deactivate or activate all the breakpoints listed in the Breakpoints pane without removing them, toggle the breakpoint activation switch at the right side of the Scripts panel toolbar.
- To remove a breakpoint, locate and click the breakpoint marker in the line gutter of the document pane. The marker no longer appears in the line gutter, and the breakpoint is removed from the Breakpoints pane.