Elevate JavaScript with LWS Trusted Mode
Before you can set up trusted mode, you must Contact Salesforce Support to Turn on LWS Trusted Mode.
To elevate third-party scripts to run in the global context, you must perform admin tasks in the org and developer tasks in your component code. These tasks together enable trusted mode for a third-party script library.
Trusted mode doesn’t enable all static resources to run outside LWS and Lightning Locker. After admins enable trusted mode, they must then specify individual static resources that can be used in trusted mode. Furthermore, developers that use the trusted mode static resource must explicitly modify their component code to use the library’s APIs in trusted mode.
Perform these admin tasks in the org to enable components to use third-party scripts in trusted mode.
- In Setup, enter
Static Resourcesin the Quick Find field, and select Static Resources. - Create a new static resource and upload the third-party code to Salesforce. For more information, see Access Static Resources in the Lightning Web Components Developer Guide.

-
In Setup, enter
Sessionin the Quick Find field, and select Session Settings. -
In the Lightning Web Security section, select Turn on Trusted Mode for third-party static resources.
If you don’t see this option, you must Contact Salesforce Support to Turn on LWS Trusted Mode.

-
Save the setting. The Setup Home page reloads.
-
Select Session Settings again. In the Lightning Web Security section, review the caution message that now appears. You are responsible for the security of any code you use in trusted mode.

-
A Static Resources area also appears. In the Name field, enter the name of the static resource to run in trusted mode. The name must exactly match the name of the static resource. Setup doesn’t validate the name in this field. A typo in the name won’t surface until you run the component code that imports the resource.
-
If the static resource has a namespace prefix, enter it in the Namespace Prefix field.
-
Click Add Trusted Resource.

Session settings are saved automatically as Setup adds the static resource to the list.
- After the Setup Home page reloads, select Session Settings again and confirm that the static resource is included in the Static Resources list.

Now you’re ready to set up your component to use the third-party script running in trusted mode.
Before you can use trusted mode, you must Contact Salesforce Support to Turn on LWS Trusted Mode.
Perform these developer tasks in the component code where you want to use the trusted static resource.
-
Import
loadScriptfrom thelightning/platformResourceLoadermodule. -
Import the static resource from the resource module that the admin enabled for trusted mode.
import myResourceName from '@salesforce/resourceUrl/myResourceName'; -
Load scripts from the static resource into an LWC component with the
loadScriptfunction from thelightning/platformResourceLoadermodule. -
With the
loadScriptfunction, include theconfigobject parameter containing two properties.trustedMode, a Boolean set totrue.trustedGlobals, an array containing the names of global properties that the component can access within the sandbox.
The component code running in the LWS sandbox can access the properties specified in trustedGlobals in the global context, unblocked by LWS or Locker.
See Also