Use the Sources panel to debug JavaScript. Before you start debugging, please take some time to familiarize yourself with the Lynx JavaScript Runtime.
After DevTool is enabled, the background thread uses the PrimJS engine for debugging by default. On Android, you can also switch to the V8 engine for a more comprehensive debugging experience.
To switch to the V8 engine, open the DevTool Switch Page, toggle the "V8 Engine" switch to "On" and restart the application. You can check the current engine type in the lower-left corner of the Preview Window.
The Sources panel has three sections:
You can use the File Navigation Pane or the Open file feature to open the file of interest.
You can enter the file URL here or select a file from the drop-down list.
The bottom status bar of the Code Editor Pane will display the line and column number of the current mouse position.
You can close a file in the following ways:
To locate the file currently displayed in the Code Editor Pane:
To search a code segment:
You can also:
By adding breakpoints, you can pause the code execution and inspect all relevant values at that moment.
Currently supported breakpoint types are as follows:
Type | Description |
---|---|
Line-of-code | Pause on an exact region of code. |
Conditional line-of-code | Pause on an exact region of code, but only when some other condition is true. |
Logpoint | Log a message to the Console without pausing the execution. |
First line | Pause on the first line of every executed JavaScript file. |
Exception | Pause on the line of code that is throwing a caught or uncaught exception. |
Please refer to Line-of-code breakpoints | Chrome DevTools.
Please refer to Line-of-code breakpoints in your code | Chrome DevTools.
Please refer to Conditional line-of-code breakpoints | Chrome DevTools.
Please refer to Log line-of-code breakpoints | Chrome DevTools.
Right-click the breakpoint icon or use the Breakpoints pane to manage line-of-code breakpoints.
Right-click the breakpoint icon and select Edit breakpoint to edit it. You can also change its type from the drop-down list in the inline editor.
Click the breakpoint icon again to delete the breakpoint.
In the Breakpoints pane, click the checkbox next to the breakpoint entry to enable or disable the breakpoint. When disabled, the marker next to the line number will become transparent.
Right-click the breakpoint icon to see the options menu:
Right-click the breakpoint entry in the Breakpoints pane to see the options menu:
Please refer to Skip breakpoints with 'Never pause here' | Chrome DevTools.
Use first-line breakpoints to pause at the entry of every executed JavaScript file.
Hover your mouse over the position shown in the image, then enable First-Line Breakpoints. This is a non-persistent global switch that takes effect for all pages during a single APP run. The switch state will be reset after closing and restarting the APP.
You can debug first-line breakpoints in two ways:
Use exception breakpoints when you want to pause on the line of code that's throwing a caught or uncaught exception.
Currently, the PrimJS engine does not distinguish between caught and uncaught exceptions, and all exceptions will cause a pause. In contrast, the V8 engine distinguishes between caught and uncaught exceptions.
By default, you can only debug the background thread. If you need to debug the main thread, please refer to the section Debug the Main Thread.
Once your code is paused, step through it, one expression at a time, investigating control flow and property values along the way.
Please refer to Step over line of code | Chrome DevTools.
Please refer to Step into line of code | Chrome DevTools.
Please refer to Step out of line of code | Chrome DevTools.
Please refer to Run all code up to a certain line | Chrome DevTools.
Please refer to Resume script execution | Chrome DevTools.
To stop your script's execution after a pause, click and hold the Resume button and then select Terminate script execution button.
For example, in this case, select Terminate script execution, DevTool will
stop executing the script, the rest of the code in add
will not be executed,
and you will see that the value of count
will not change.
Please refer to View and edit local, closure, and global properties | Chrome DevTools.
When paused on a line of code, you can use the Call Stack pane to view the call stack that got you to this point.
Select an entry in the pane to jump to the line of code where the function was called. A blue arrow icon represents the currently highlighted code.
Right-click anywhere in the Call Stack pane and select Copy stack trace to copy the current call stack to the clipboard.
For example, in this case, the copied stack trace is as follows:
Ignore certain scripts during debugging to skip them. When ignored, scripts will be hidden in the Call stack pane, and you will never step into functions from ignored scripts while stepping through code.
Please refer to Ignore a script from the Editor pane | Chrome DevTools.
Please refer to Ignore a script from the Call Stack pane | Chrome DevTools.
If you need to view the complete call stack, click Show ignore-listed frames in the Call Stack pane. The ignored frames will be expanded but displayed in gray.
To unignore scripts, follow the same steps as above and select Remove from ignore list.
You can also unignore scripts through the prompt at the top of the Code Editor Pane.
Please refer to Watch the values of custom JavaScript expressions | Chrome DevTools.
In the Code Editor Pane, you can browse and edit code.
Click the {}
button in the bottom status bar of the editor, and the Sources panel will present the minified file in a more readable format to improve readability.
Please refer to Edit a script | Chrome DevTools.
You can only modify compiled JavaScript files. The original files reversed through SourceMap cannot be modified, and changes will not be saved after reloading the page.
Please refer to Search and replace text in a script | Chrome DevTools.
After replacing, you need to manually save the script, as referenced in Edit Scripts.
After configuring SourceMap, you can directly debug the original code you author in the Sources panel.
When you open DevTool, it attempts to load source maps, if any.
After loading successfully, the files in the File Navigator Pane with orange folders are the original source files.
If loading fails, the Console logs an error similar to the following.
When you open any compiled file, DevTool will notify you if it found the source map.
You can manually load a source map:
Debugging the main thread is similar to debugging the background thread, but it requires some additional steps to enable.
To debug the main thread, you need to start the project in dev mode using rspeedy.
You can check the following two items to ensure preparation is done:
debug-info.json
file is generated in the intermediate output directory.
tasm.json
file of the intermediate output directory, the templateDebugUrl
field is a valid URL pointing to the debug-info.json
file mentioned in step one. Refer to rspeedy.dev.assetprefix.
Hover over the position shown in the image below, then enable Main Thread Debugging. This is a non-persistent global switch that takes effect for all pages during a single APP run. The switch state will be reset after closing and restarting the APP.
To enable main thread debugging:
main-thread.js
file of the main thread will be displayed in the File Navigator Pane (formerly known as lepus.js
).In the Threads pane, you can switch between debugging the main thread or the background thread. The blue arrow icon represents which context is selected. The currently paused thread will be marked as paused.