> For AI agents: the complete documentation index is available at /next/llms.txt, the full documentation bundle is available at /next/llms-full.txt.


# Sources Panel

Use the **Sources** panel to debug JavaScript. Before you start debugging, please take some time to familiarize yourself with the [Lynx JavaScript Runtime](/next/guide/scripting-runtime/index.md#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](/next/guide/start/integrate-lynx-devtool-advanced.md#debugging-devtool-switch), 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](/next/guide/devtool/panels/elements-panel.md#introduction-to-the-preview-panel).

## Overview

The **Sources** panel has three sections:

1. **File Navigation Pane**. All JavaScript files of the page are listed here.
2. **Code Editor Pane**. After selecting a file in the **File Navigation Pane**, the contents of the file are displayed here.
3. **Debugger Pane**. Various tools for inspecting the page's JavaScript.

![Sources panel](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/sources-panel.png)
## File Navigation

### Open File

You can use the **File Navigation Pane** or the **Open file** feature to open the file of interest.

Click **More Options**&#x20;

![More options](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/more-options.png)
and select **Open file**. A dialog will display.

![Open file](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/open-file.png)
You can enter the file URL here or select a file from the drop-down list.

![Open file dialog](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/open-file-dialog.png)
The bottom status bar of the **Code Editor Pane** will display the line and column number of the current mouse position.

Click **Show navigator**&#x20;

![Watch Add](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/show-navigator.png)
button to collapse/expand the **File Navigation Pane**.

![File editor](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/file-editor.png)
### Close File

You can close a file in the following ways:

- Hover the mouse over the file name tab at the top of the **Code Editor Pane** and click the **close** button.
  ![Close file button](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/close-file-button.png)
- Right-click the file name tab at the top of the **Code Editor Pane**:
  - Close: Close the current file.
  - Close others: Close other files.
  - Close all: Close all files.
    ![Close file](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/close-file.png)

### Locate File

To locate the file currently displayed in the **Code Editor Pane**:

1. Right-click anywhere in the **Code Editor Pane** or right-click the file name tab at the top of the **Code Editor Pane**.
2. Select **Reveal in sidebar**.

![Reveal in sidebar](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/reveal-in-sidebar.png)
### Search Code

To search a code segment:

1. Click **Customize And Control DevTools** ![More options](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/more-options.png) \> **Search** to open the **Search** panel.

   ![Search](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/search.png)

2. Enter text and press Enter to search.

3. Click search results to jump to the corresponding file and the code will be highlighted.

   ![Search panel](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/search-panel.png)

You can also:

- Click **Match Case** ![Match Case](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/match-case.png) to make the query case-sensitive.
- Click **Use Regular Expression** ![Use Regular Expression](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/use-regular.png) to search using a RegEx.
- Click **Refresh** ![Refresh](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/refresh.png) to search again.
- Click **Clear** ![Clear](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/clear.png) to clear the input contents.

## Pause Code with Breakpoints

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](#line-of-code-breakpoints)             | Pause on an exact region of code.                                             |
| [Conditional line-of-code](#conditional-line-of-code-breakpoints) | Pause on an exact region of code, but only when some other condition is true. |
|             [Logpoint](#log-line-of-code-breakpoints)             | Log a message to the Console without pausing the execution.                   |
|               [First line](#first-line-breakpoints)               | Pause on the first line of every executed JavaScript file.                    |
|                [Exception](#exception-breakpoints)                | Pause on the line of code that is throwing a caught or uncaught exception.    |

### Line-of-Code Breakpoints

Please refer to [Line-of-code breakpoints | Chrome DevTools](https://developer.chrome.com/docs/devtools/javascript/breakpoints#loc).

#### Line-of-Code Breakpoints in Code

Please refer to [Line-of-code breakpoints in your code | Chrome DevTools](https://developer.chrome.com/docs/devtools/javascript/breakpoints#debugger).

#### Conditional Line-of-Code Breakpoints

Please refer to [Conditional line-of-code breakpoints | Chrome DevTools](https://developer.chrome.com/docs/devtools/javascript/breakpoints#conditional-loc).

#### Log Line-of-Code breakpoints

Please refer to [Log line-of-code breakpoints | Chrome DevTools](https://developer.chrome.com/docs/devtools/javascript/breakpoints#log-loc).

#### Manage Line-of-Code Breakpoints

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.
  ![Edit breakpoint](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/edit-bp.png)

- 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.

  ![Disable breakpoint](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/disable-bp.png)

- Right-click the breakpoint icon to see the options menu:
  - Remove breakpoint.
  - Edit breakpoint.
  - Disable/Enable breakpoint.
    ![Breakpoint action](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/bp-action.png)

- Right-click the breakpoint entry in the **Breakpoints** pane to see the options menu:
  - Remove breakpoint.
  - Reveal location.
  - Deactivate/Activate breakpoints.
    You can also use **Deactivate breakpoints**&#x20;

![Step out](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/deactivate-bp.png)
button to deactivate breakpoints.

    When breakpoints are deactivated, DevTool will ignore all line-of-code
    breakpoints, and they will not be triggered. All breakpoints will remain in
    the same state after being reactivated.
  - Disable/Enable all breakpoints.
  - Disable/Enable breakpoints in file.
  - Remove all breakpoints.
  - Remove other breakpoints.
    ![Breakpoint pane action](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/bp-pane-action.png)

#### Skip Breakpoints with 'Never Pause Here' Background V8 Only

Please refer to [Skip breakpoints with 'Never pause here' | Chrome DevTools](https://developer.chrome.com/docs/devtools/javascript/breakpoints#never-pause-here).

### First-Line Breakpoints Background Only

Use first-line breakpoints to pause at the entry of every executed JavaScript file.

![First line breakpoint example](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/first-line-bp-example.png)
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.

![First line breakpoint](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/first-line-bp.png)
You can debug first-line breakpoints in two ways:

1. Turn on the switch, then open the page you want to debug.
2. Open the page you want to debug, turn on the switch, and then [reload](/next/guide/devtool/panels/elements-panel.md#introduction-to-the-preview-panel) the page.

### Exception Breakpoints

Use exception breakpoints when you want to pause on the line of code that's throwing a caught or uncaught exception.

1. In the **Breakpoints** pane, click the **Pause on exceptions** button, which turns blue when enabled.
2. By default, it only pause on uncaught exceptions. If you also want to pause on caught exceptions, check the **Pause On Caught Exceptions** checkbox.

![Pause on exceptions](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/pause-on-exceptions.png)
:::warning

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.

:::

## Debug JavaScript

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](#debug-the-main-thread).

### Step Through Code

Once your code is paused, step through it, one expression at a time, investigating control flow and property values along the way.

![Pause](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/pause.png)
#### Step Over

Please refer to [Step over line of code | Chrome DevTools](https://developer.chrome.com/docs/devtools/javascript/reference#step-over).

#### Step Into

Please refer to [Step into line of code | Chrome DevTools](https://developer.chrome.com/docs/devtools/javascript/reference#step-into).

#### Step Out

Please refer to [Step out of line of code | Chrome DevTools](https://developer.chrome.com/docs/devtools/javascript/reference#step-out).

#### Run All Code Up to a Certain Line Background V8 Only

Please refer to [Run all code up to a certain line | Chrome DevTools](https://developer.chrome.com/docs/devtools/javascript/reference#continue-to-here).

#### Resume

Please refer to [Resume script execution | Chrome DevTools](https://developer.chrome.com/docs/devtools/javascript/reference#resume).

##### Terminate Execution Background V8 Only

To stop your script's execution after a pause, click and hold the **Resume** button and then select **Terminate script execution** button.

![Terminate script execution example](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/terminate-execution-example.png)
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.

### View and Edit Properties

Please refer to [View and edit local, closure, and global properties | Chrome DevTools](https://developer.chrome.com/docs/devtools/javascript/reference#scope).

### View the Current Call Stack

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.

![Call stack](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/call-stack.png)
#### Copy Stack Trace

Right-click anywhere in the **Call Stack** pane and select **Copy stack trace** to copy the current call stack to the clipboard.

![Copy stack trace](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/copy-stack-trace.png)
For example, in this case, the copied stack trace is as follows:

```
add (App.tsx:11)
publishEvent (tt.js:148)
```

### Ignore Scripts Background V8 Only

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.

#### Ignore a Script from the Editor Pane

Please refer to [Ignore a script from the Editor pane | Chrome DevTools](https://developer.chrome.com/docs/devtools/javascript/reference#editor-ignore-list).

#### Ignore a Script from the Call Stack Pane

Please refer to [Ignore a script from the Call Stack pane | Chrome DevTools](https://developer.chrome.com/docs/devtools/javascript/reference#call-stack-ignore-list).

#### Show ignore-listed frames

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.

![Show ignore1](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/show-ignore1.png)


![Show ignore2](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/show-ignore2.png)
#### Unignore Scripts

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**.

![Remove ignore](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/remove-ignore.png)
### Watch the Values of Custom JavaScript Expressions

Please refer to [Watch the values of custom JavaScript expressions | Chrome DevTools](https://developer.chrome.com/docs/devtools/javascript/reference#watch).

### Inspect and Edit Scripts

In the **Code Editor Pane**, you can browse and edit code.

#### Make Minified Files Readable

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.

![Format before](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/format-before.png)


![Format after](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/format-after.png)
#### Edit Scripts Background V8 Only

Please refer to [Edit a script | Chrome DevTools](https://developer.chrome.com/docs/devtools/javascript/reference#edit).

:::warning
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.
:::

#### Search and Replace Text in Scripts

Please refer to [Search and replace text in a script | Chrome DevTools](https://developer.chrome.com/docs/devtools/javascript/reference#search).

After replacing, you need to manually save the script, as referenced in [Edit Scripts](#edit-scripts).

## Debug Original Code with Source Maps Background Only

After [configuring SourceMap](/next/api/build/output/source-map.md), you can directly debug the original code you author in the Sources panel.

### Check If Source Maps Loaded Successfully

#### Check Load Status

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.

![Original files](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/original-files.png)
If loading fails, the **Console** logs an error similar to the following.

![Sourcemap fail](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/sourcemap-fail.png)
When you open any compiled file, DevTool will notify you if it found the source map.

![Sourcemap detected](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/sourcemap-detected.png)
#### Load a Source Map Manually

You can manually load a source map:

1. Open the compiled file, right-click anywhere in the **Code Editor Pane**, and select **Add source map**.
   ![Add sourcemap1](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/add-sourcemap1.png)
2. Enter the source map URL in the textbox, then click **Add**.
   ![Add sourcemap2](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/add-sourcemap2.png)

### Debug with Source Maps

1. In the original file, you can [set breakpoints](#pause-code-with-breakpoints) as you normally would, or you can set breakpoints in the compiled file, and DevTool will automatically jump to the original file.
2. After triggering a breakpoint and pausing, the **Call Stack** pane will display the name of the original file.
   ![Original file stack](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/original-file-stack.png)
3. The bottom status bar of the **Code Editor Pane** will show a link to the compiled file it points to. Click it to jump to the corresponding file.
   ![Sourcemap from](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/sourcemap-from.png)

## Debug the Main Thread

Debugging the main thread is similar to debugging the background thread, but it requires some additional steps to enable.

### Preparation

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:

1. A `debug-metadata.json` file is generated in the intermediate output directory (`dist/.lynx/<entry>/`).
   ![Debug metadata](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/doc/devtool/sources/debug-metadata.png)
2. In the `tasm.json` file of the same directory, the `sourceContent.config.debugMetadataUrl` field is a valid URL pointing to the `debug-metadata.json` file mentioned in step one. Refer to [rspeedy.dev.assetprefix](https://rsbuild.rs/config/dev/asset-prefix).
   ![Debug metadata url](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/doc/devtool/sources/debug-metadata-url.png)

### Enable Main Thread Debugging

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.

![Main thread debugging](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/main-thread-debugging.png)
To enable main thread debugging:

1. Turn on the switch, then open the page you want to debug. Or open the page you want to debug, turn on the switch, and then [reload](/next/guide/devtool/panels/elements-panel.md#introduction-to-the-preview-panel) the page.
2. The `main-thread.js` file of the main thread will be displayed in the **File Navigator Pane** (formerly known as `lepus.js`).
3. In the **Threads** pane, switch to **Main** to start debugging.

![Main target](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/sources/main-target.png)
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**.

## Compatibility

### Breakpoints

**Compatibility Table**

**Query:** `devtool.panels.sources.breakpoints`

[Source](https://github.com/lynx-family/lynx-website/tree/main/packages/lynx-compat-data/devtool/panels.json)

| Feature | Android | HarmonyOS | iOS | macOS | Windows | Web |
| --- | --- | --- | --- | --- | --- | --- |
| BTS | Yes (3.0) | Yes (3.0) | Yes (3.0) | Unknown | Unknown | No |
| MTS | Yes (3.0) | Yes (3.5) | Yes (3.0) | Unknown | Unknown | No |

**`BTS`**

Background thread breakpoints

**`MTS`**

Main thread breakpoints


### JS Engine

**Compatibility Table**

**Query:** `devtool.panels.sources.JSEngine`

[Source](https://github.com/lynx-family/lynx-website/tree/main/packages/lynx-compat-data/devtool/panels.json)

| Feature | Android | HarmonyOS | iOS | macOS | Windows | Web |
| --- | --- | --- | --- | --- | --- | --- |
| PrimJS | Yes (3.0) | Yes (3.0) | Yes (3.0) | Unknown | Unknown | No |
| V8 | Yes (3.0) | No | No | Unknown | Unknown | No |

**`PrimJS`**

PrimJS

**`V8`**

V8

