JavaScript (JS) errors directly affect the quality of applications. Therefore, JS errors must be located and diagnosed. The JS error diagnostics capability provided by the frontend monitoring feature of Application Real-Time Monitoring Service (ARMS) can accurately locate and diagnose JS errors with efficiency.
Prerequisites
Background information
- Difficult to replicate.
For example, when User A visits a page, the page is loaded on the browser of User A. The time consumed for loading the page is affected by factors such as the region, network, browser, and carrier. Therefore, the actual situation that occurred when User A accessed the page is difficult to be replicated.
- Lack of monitoring information for in-depth investigation.
Most frontend monitoring projects use the PerformanceTiming object to obtain the loading time of the full page, which excludes the loading time of static resources. Therefore, performance bottlenecks cannot be identified.
The ARMS frontend monitoring feature can use the source map to find the real location of the error in code and use the user behavior backtracking feature to replicate the JS error. This allows developers to locate errors in the source code and corresponding code blocks with efficiency.
Step 1: Install an ARMS agent
To comprehensively monitor applications, you must install the ARMS agent for your applications. Select a method to install the ARMS agent as needed. For more information, see Browser monitoring overview.
Step 2: View the error overview
Step 3: Diagnose a specific error
- On the Frequent Errors tab, click Diagnose to go to the diagnostics page.
- In the curve chart, go to the Exception Insight dialog box at a specific point in time and then go to the diagnostics page.
The second method is used as an example in this topic.
Step 4: View error details
JS error details include the first occurrence time, version for the first occurrence (optional), error name, error type, point in time of the occurrence, device, operating system, browser, IP address, connection type, region, error URL, and application version. The details also include the file, line, and column where the error occurs. The map module on the real-time dashboard reported an error of invalid data during the update, and the error occurred in Line 1 and Column 79585, as shown in the following figure.

Step 5: Locate the error in the source code
The information acquired from the JS error details is insufficient for error diagnostics, because online code is unreadable after compilation, compression, and obfuscation. Although you can see the error occurred in Line 1 and Column 79585, this does not specify the actual location in the source code. In this case, you must use the source map for source code mapping.
Step 6: View the backtracked user behaviors
As shown in the source code mapping, the source code error occurred when invalid data was loaded during the creation of the map component. However, invalid data may appear in a variety of forms. Null judgment and fault tolerance have been performed for data in the source code, but the exception of invalid data is still triggered. If a snapshot can be taken for the data of the error, you can locate the error more accurately. However, onsite data is usually unavailable in global exception capture, and troubleshooting depends only on the data information that is reported with the exception.
The best way is to replicate the error. The ARMS frontend monitoring feature defines event nodes on a page as user behaviors, such as page loading, route jumps, page clicks, API requests, and console output. User behaviors are connected in chronological order to form a behavior trace. Behavior backtracking upon the error can help developers replicate the error.
The user behavior backtracking upon the error shows that an API request was made before the error occurred, as shown in the following Figure 1 figure. This API request tried to request the real-time update of the map module, but the returned data is ConsoleNeedLogin. This indicates that the user has logged off from the page. This is the root cause of invalid data.
