# Debug with Lightning Web Security Enabled

To debug Lightning components in an org where Lightning Web Security (LWS) is enabled, first [enable debug mode](/docs/platform/lwc/guide/debug-mode-enable.md). With [debug mode](/docs/platform/lwc/guide/debug-debug-mode.md), JavaScript code is easier to read because it isn’t optimized or minified. Debug mode also adds more detailed output for some warnings and errors.

To inspect your client-side code, we recommend using [Chrome DevTools](https://developer.chrome.com/docs/devtools/). To open DevTools on Windows and Linux, press Control-Shift-I in your Google Chrome browser. On Mac, press Option-Command-I.

## Source Code Location for LWC Debugging Under LWS

Beginning in Winter ’24, as you debug Lightning web components with Chrome DevTools, your component source code is displayed in the Sources panel inside the `lightning/n/modules` folder. This location is described in the [Find Your Code in the Sources Panel](/docs/platform/lwc/guide/debug-dev-tools.md#find-your-code-in-the-sources-panel) section of the *Lightning Web Components Developer Guide*. The location is the same regardless of whether Lightning Locker or LWS is enabled.

Previously, when your Lightning web components ran in an org where Lightning Web Security was enabled, a special `lws` folder separately organized your component files under a namespace folder.

![Source files in Page pane](https://a.sfdcstatic.com/developer-website/sfdocs/lwc/media/debug_source_debug_mode_lws.png)

Here you see the `c` namespace and its components on the current page. The `compositionBasics.js` file with LWS enabled is shown with source mapping.

Source mapping enables the sandboxed code to appear similar to your components’ original source code. You can inspect it, use breakpoints, and so on. You must enable debug mode to see the source mapping and to enable breakpoints.

:::tip
If the code in the Sources panel doesn’t look like your original source code, make sure the setting **Enable JavaScript source maps** in Chrome DevTools is enabled. It’s enabled by default.
:::

You can also find the source file in the Page pane when you’re already in the debugger. Right-click and select **Reveal in sidebar**.

Here the debugger stopped in `compositionContactSearch.js`, but the file is not selected in the sidebar. When you select **Reveal in sidebar**, the correct file is selected.

![Context menu with Reveal in sidebar option](https://a.sfdcstatic.com/developer-website/sfdocs/lwc/media/debug_reveal_sidebar.png)

## Source Code Location for Aura Component Debugging Under LWS

When you’re debugging Aura components, the source code is displayed in the Sources panel in the `lightning/n/components` subfolder inside a folder named for the org.

The `lightning/n/components` folder’s exact location can vary between browsers and sessions, and is also dependent on how you use the component. If you don’t see the folder right away, expand the nodes until you find it.

This example shows the Aura Interop component from lwc-recipes. The top folder name `Aura_Interoperability` matches the name of the Lightning page that contains the component. The highlighted file is used for debugging.

![Aura source file used for debugging](https://a.sfdcstatic.com/developer-website/sfdocs/lwc/media/lws_aura_debug.png)

## Console Stack Traces

The stack trace in the Console filters out LWS calls to give you a clearer picture of errors in your components. The LWS calls are contained in their own folder (1).

![LWS folder in console](https://a.sfdcstatic.com/developer-website/sfdocs/lwc/media/debug_lws_stack_trace.png)

To see filtered stack traces, enable custom formatters as described the [Enable Custom Formatters](/docs/platform/lwc/guide/debug-dev-tools.md#enable-custom-formatters) section of the *Lightning Web Components Developer Guide*.

## Console Messages

Console messages show information about LWS in console methods such as `console.warn` and `console.info`. For example, `console.warn` is called when an object mutation is tracked on one side of the sandbox and not the other.

To see LWS console messages, enable custom formatters as described in the [Enable Custom Formatters](/docs/platform/lwc/guide/debug-dev-tools.md#enable-custom-formatters) section of the *Lightning Web Components Developer Guide*.

:::note
LWS changes the source code line number and source code file for console messages. Console messages appear to come from the Salesforce `aura_proddebug.js` file instead of from the component’s JavaScript file that logs the message. This behavior is a known issue that is due to browser implementations so we’re waiting for browser vendors to implement a fix.
:::

**See Also**

- [Limitations for Debugging with LWS Enabled](/docs/platform/lightning-components-security/guide/lws-debug-limitations.md)
- [*Lightning Web Components Developer Guide*: Debug Lightning Web Components](/docs/platform/lwc/guide/debug-intro.md)
- [*Lightning Web Components Developer Guide*: Debug Using Chrome DevTools](/docs/platform/lwc/guide/debug-dev-tools.md)
- [*Lightning Aura Components Developer Guide*: Debugging](https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/debug_intro.htm)
