search
HomeWeb Front-endJS TutorialJavaScript debugging skills: breakpoint debugging_javascript skills

First of all, among various browsers, Firefox has the best support for breakpoint debugging. Firefox can not only use Firebug to debug page js scripts, but also use advanced debugging tools such as JavaScript Debugger (Venkman) to debug Firefox extensions. js. In addition, Firefox also supports some more advanced breakpoint debugging and variable monitoring functions.

Among other browsers, the debugging functions of Opera, Chrome and Safari are also relatively easy to use. Opera's DragonFly is relatively fast, has a clean interface, and has powerful functions, but it is not as user-friendly as Safari. In comparison, IE8's programmer tools are simply useless.
Time is limited this time, so let’s first summarize the debugging skills under Firefox.

1. Use Firebug for breakpoint debugging

Debugging JavaScript with Firebug is very convenient. Specific steps:

a. After opening Firebug, enable "script" debugging and find the referenced script file (or inline js);

JavaScript debugging skills: breakpoint debugging_javascript skills

Use Firebug to find the script you want to debug (click to enlarge)

b. Add breakpoints at appropriate locations;

c. If the breakpoint has been executed, refresh the page and the script will interrupt at the breakpoint. If the breakpoint has not been executed, you can directly execute the action on the page (such as clicking a button, etc.), and then the code will interrupt at the breakpoint;

JavaScript debugging skills: breakpoint debugging_javascript skills

Use Firebug for breakpoint debugging (click to enlarge)

d. Observe the function call stack, observe local variables, and perform single-step execution for debugging.

It’s really simple! The advantages of debugging with Firebug breakpoints are summarized as follows:

The lines where breakpoints can be added are numbered in green, which is very intuitive;

The call stack is displayed in two ways, which is very convenient;

The display of local variables is very clear and concise.

2. Use JavaScript Debugger for breakpoint debugging

This is an old debugging tool, formerly called Venkman, which can be installed on Firefox in the form of an extension. Let’s call it Venkman here. It can not only debug page scripts, but also debug js in Firefox extensions. When we are doing Firefox extension development, Venkman is an indispensable tool, Lao Tian strongly recommends it! Of course, the logic implementation of Firefox itself is also done in JavaScript. We can now use Venkman to debug Firefox itself. The core js of Firefox is browser.js, which is under this path:

chrome://browser/content/browser.js

After we open Venkman, fill in browser.js in Loaded Scripts, and this js file will be filtered out (if you don’t see browser.js, you may need to check whether Debug->Exclude is selected browser files).

JavaScript debugging skills: breakpoint debugging_javascript skills

Venkman: Select the js file to be debugged (click to enlarge)

We find the code that makes the browser go back, and then click the Firefox back button. At this time, Venkman will stop at the BrowserBack method! Let's take a step-by-step look at what Firefox does. btw, isn’t the js code that implements Firefox very beautiful~~~

用JavaScript Debugger调试Firefox

Debug Firefox with JavaScript Debugger breakpoints (click to enlarge)

Of course Venkman also comes with a console. Using this console, we can take a look at what the window and document are at the browser level. Similar to the console of Firebug and other browsers, just enter the js code snippet directly!

JavaScript debugging skills: breakpoint debugging_javascript skills

Use the console that comes with Venkman (click to enlarge)

If you are interested, you can discover more interesting things about Firefox development (and extension development) here!

3. Use debugger to add breakpoints in the program

There is also a little-known method of adding breakpoints. We can add a debugger statement to the program, so that Firefox's debugging tool will stay on this statement and the code will pause execution, which has the same effect as adding a breakpoint. For example:

var myfunc = {
 get_field_value_callback : function() {
  debugger;
  var ed = this, target = ed.currSpan;
  /* do something more */
 }
}

When the page is reloaded, the breakpoint will stay on the debugger statement. In this way, we can add breakpoints as we like when writing code. In addition, other browsers (including IE8! Surprise!) also support the debugger statement!

Last time I summarized the techniques for debugging JavaScript breakpoints under Firefox. This time we will look at debugging under other browsers. A little explanation, the debugging skills here do not rely on tools other than the browser, such as Aptana, VS2008, etc. If you are looking for some information on this, I don’t have it here.

Other browsers, mainly Opera, Safari, Chrome and IE8. Except for IE8, their debugging functions are quite good. You can basically search scripts, add breakpoints, view call stacks, local variables, and powerful consoles.

1. Use Opera’s Dragonfly for breakpoint debugging

JavaScript debugging skills: breakpoint debugging_javascript skills

Use Opera Dragonfly for breakpoint debugging

Open Tools – Advanced – Developer Tools, and you will see a development tool similar to Firebug, called Dragonfly, which is dragonfly. Here you can view the page structure, view network interactions, and breakpoint debugging, and you can use the Command Line (console) during the debugging process.

Opera on WindowsXP is also an A-grade that YUI needs to support (see this table for details), so we must try our best to support it when developing. In addition, Dragonfly's DOM viewing tool has a highlight, Export current DOM view. We can make some DOM changes online and then export them to get the changed HTML code, which is very convenient.

2. Use Chrome and Safari for breakpoint debugging

If you think Opera is too niche, you can debug it on Safari or Chrome. The debugging methods and interfaces of the two browsers are very similar, so here we take Safari 4.0 as an example. Open Menu – Develop – Start Debugging JavaScript, and a debugging tool will pop up. It is worth mentioning that it is best not to dock the debugging tools of Safari and Chrome under the browser, because if they pop up, the debugging interface will be just right.
First find the script you want to debug:

JavaScript debugging skills: breakpoint debugging_javascript skills

JavaScript debugging with Safari: Find the script

Set a breakpoint and reload the page (or perform an action):

JavaScript debugging skills: breakpoint debugging_javascript skills

JavaScript debugging with Safari: Setting breakpoints

View local variables and function call stack on the right:

JavaScript debugging skills: breakpoint debugging_javascript skills

JavaScript Debugging with Safari: Variable View

A highlight of Safari’s debugging tool is that the console and breakpoint debugging are on the same interface, which makes it very convenient to use the console to do some verification operations when the program is interrupted.

3. Breakpoint debugging function of IE8

The developer tools that come with IE8, although extremely difficult to use, can also be used for breakpoint debugging. The method of breakpoint debugging is similar to the above.

JavaScript debugging skills: breakpoint debugging_javascript skills

Use IE8 developer tools for breakpoint debugging

As you can see, IE8 seems to have terminated the recognition of js code inexplicably. In this case, there is no way to add breakpoints from line 74 onwards, which is incredible. But sometimes in order to be compatible with IE, we have to do some debugging under IE. What should we do? You can use the method in the previous article to add a debugger statement where the interruption is needed, so that when the program is running, IE8 will interrupt on the debugger statement.

The above content is the JavaScript debugging skills shared by the editor - Firefox power-off debugging. I hope you like it.

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Replace String Characters in JavaScriptReplace String Characters in JavaScriptMar 11, 2025 am 12:07 AM

Detailed explanation of JavaScript string replacement method and FAQ This article will explore two ways to replace string characters in JavaScript: internal JavaScript code and internal HTML for web pages. Replace string inside JavaScript code The most direct way is to use the replace() method: str = str.replace("find","replace"); This method replaces only the first match. To replace all matches, use a regular expression and add the global flag g: str = str.replace(/fi

Custom Google Search API Setup TutorialCustom Google Search API Setup TutorialMar 04, 2025 am 01:06 AM

This tutorial shows you how to integrate a custom Google Search API into your blog or website, offering a more refined search experience than standard WordPress theme search functions. It's surprisingly easy! You'll be able to restrict searches to y

Build Your Own AJAX Web ApplicationsBuild Your Own AJAX Web ApplicationsMar 09, 2025 am 12:11 AM

So here you are, ready to learn all about this thing called AJAX. But, what exactly is it? The term AJAX refers to a loose grouping of technologies that are used to create dynamic, interactive web content. The term AJAX, originally coined by Jesse J

Example Colors JSON FileExample Colors JSON FileMar 03, 2025 am 12:35 AM

This article series was rewritten in mid 2017 with up-to-date information and fresh examples. In this JSON example, we will look at how we can store simple values in a file using JSON format. Using the key-value pair notation, we can store any kind

10 jQuery Syntax Highlighters10 jQuery Syntax HighlightersMar 02, 2025 am 12:32 AM

Enhance Your Code Presentation: 10 Syntax Highlighters for Developers Sharing code snippets on your website or blog is a common practice for developers. Choosing the right syntax highlighter can significantly improve readability and visual appeal. T

8 Stunning jQuery Page Layout Plugins8 Stunning jQuery Page Layout PluginsMar 06, 2025 am 12:48 AM

Leverage jQuery for Effortless Web Page Layouts: 8 Essential Plugins jQuery simplifies web page layout significantly. This article highlights eight powerful jQuery plugins that streamline the process, particularly useful for manual website creation

10  JavaScript & jQuery MVC Tutorials10 JavaScript & jQuery MVC TutorialsMar 02, 2025 am 01:16 AM

This article presents a curated selection of over 10 tutorials on JavaScript and jQuery Model-View-Controller (MVC) frameworks, perfect for boosting your web development skills in the new year. These tutorials cover a range of topics, from foundatio

What is 'this' in JavaScript?What is 'this' in JavaScript?Mar 04, 2025 am 01:15 AM

Core points This in JavaScript usually refers to an object that "owns" the method, but it depends on how the function is called. When there is no current object, this refers to the global object. In a web browser, it is represented by window. When calling a function, this maintains the global object; but when calling an object constructor or any of its methods, this refers to an instance of the object. You can change the context of this using methods such as call(), apply(), and bind(). These methods call the function using the given this value and parameters. JavaScript is an excellent programming language. A few years ago, this sentence was

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment