Add the #DF24 Developer Keynote to your agenda. Join us in-person on 9/19 at 2:30 p.m. PT or on Salesforce+ at 5 p.m. PT for the must-see session built just for developers.

Debug with Distortions Disabled

You can use commands in your browser’s developer console to switch LWS distortions off and on for certain APIs while you debug. It can be helpful to observe how your component’s behavior changes when you disable distortions on a particular API and then enable them again.

Before you can disable distortions, you must enable debug mode for your username in the org. Then you can set flags in the browser's developer console to disable and enable distortions on APIs.

The distortion flags are most useful if you set them when the execution is paused, such as when you hit a breakpoint. We recommend using this workflow:

  1. Identify a point in your code that you want to debug and set a breakpoint.
  2. Refresh the browser page and walk through the steps needed to reach that breakpoint.
  3. When execution pauses at the breakpoint, go to the console and disable distortions that you suspect are affecting your code.
  4. Allow the code execution to continue and observe if the behavior of your code changes with the distortions disabled.

To disable and enable distortions for a given API, use $LWS.namespaces commands in the browser’s developer console to set the values of corresponding distortion flags.

You can work with multiple namespaces that are present in your org. The commands target distortions in the namespace you specify.

The command syntax is:

$LWS.namespaces.ns.distortions.flag

where ns represents the namespace and flag represents a distortion flag name.

To list the distortion flags in the c default namespace, enter this command in the browser’s developer console and press Enter.

The list of distortion flags is collapsed initially. Click the expander icon to reveal the distortion flag names.

List of distortion flags in c

See LWS Distortion Flags for Debug Sessions for descriptions of the distortion flags.

Don’t use these deprecated flags. Disabling the distortions associated with these flags can cause your code to break in the debugger.

  • dataset
  • history
  • indexedDB
  • notification
  • performance
  • postMessage
  • style

To disable distortions for an API using one of the listed distortion flags, set the flag to false. For example, to disable distortions for the XMLHttpRequest API, type this command and press Enter.

In the developer tools’ Sources view, use the debugger panel to observe the component running with the specified LWS distortions disabled.

To enable the distortion again in the current session, set the property to true.

When you reload the page all the properties reset to true.

You can view which namespaces support disabling and enabling distortion flags in your org. The command reveals only custom namespaces. You can’t see the namespaces that Salesforce owns, for example.

Enter this command in the console:

The console displays a list of available namespaces. If you’re only using the default namespace, you see the c namespace.

List of c namespace

To see the distortion flags for a namespace, click the expander icon by the namespace.

In this example, the command shows the namespaces external and untrusted in a test org.

List of other namespaces

All namespaces support the same flags. You can set the values separately in different namespaces, whichever is appropriate for the component you’re debugging.

You can also enter a command to display the distortion flags of a namespace. This example uses the command to display distortion properties in the external namespace.

To check the current value of a distortion flag, enter a command specifying the flag name.

For example, use this command to determine if all XMLHttpRequest distortions are enabled in the c namespace.

The flags are all set to true by default.

Command shows the value of the xhr flag set to true

To disable all XMLHttpRequest distortions in the debugging session, set the xhr flag to false.

Command shows the value of the xhr flag set to false

Setting xhr to false turns off all of the security-based API distortions for XMLHttpRequest.

Here's a list of the distortion flags and the corresponding distortions that are disabled when you set the flag to false.

FlagWhat it controls
attributesAll distortions related to getAttribute, setAttribute, hasAttribute, toggleAttribute for attributes described in Distortion Viewer
cachesAll CacheStorage API distortions
cookieStoreAll CookieStore API distortions
customElementsCustomElementRegistry distortions
datasetThis flag is deprecated. Don't use it.
documentCookieDocument.prototype.cookie getter and setter distortions
documentDomainDocument.prototype.domain setter distortion
documentExecCommandDocument.prototype.execCommand distortion
domParserParseFromStringDOMParser.prototype.parseFromString distortion
elementAll Element.prototype distortions except the Element.prototype.innerHTML setter, which is controlled with the innerHTML flag
historyThis flag is deprecated. Don't use it.
indexdDBThis flag is deprecated. Don't use it.
innerHTMLElement.prototype.getInnerHTML and Element.prototype.innerHTML setter distortions
navigatorSendBeaconNavigator.sendBeacon distortion
nodeAll Node.prototype API distortions
notificationThis flag is deprecated. Don't use it.
performanceThis flag is deprecated. Don't use it.
postMessageThis flag is deprecated. Don't use it.
rangeAll Range.prototype API distortions
scriptSVGScriptElement.prototype.href setter distortion
selectionSelection.prototype API distortions
setIntervalWindow.setInterval API distortion
setTimeoutWindow.setTimeout API distortion
storageAll Storage.prototype API distortions
styleThis flag is deprecated. Don't use it.
windowFetchWindow.fetch distortion
windowFramesWindow.frames getter distortion
xhrAll XMLHttpRequest.prototype distortions

See Also