Newer Version Available
Resolve Lightning Locker Conflicts in Aura Sites
Use JavaScript Custom Events
Lightning Locker protects third-party components and custom code from interacting with resources from other namespaces, but not from the head markup. This limitation means that your head markup can contain custom code that bypasses Lightning Locker and introduces security vulnerabilities.
To address this limitation, isolate your third-party Aura and Lightning web components and custom code by using the CustomEvent constructor in your head markup. Third-party components and custom code can then interact with your resources without being responsible for loading or referencing that resource directly.
Any data that must be passed through the event to the listener is passed in the detail property, which is created when initializing the event. The detail property is mapped to the dataLayer in your head markup listener. The custom events are then dispatched to any resource that extends EventTarget. For an example of using custom events, see Adobe Analytics and Lightning Locker.
Set an Aura Component to API 39.0
If your third-party component or custom code doesn’t interact with an Aura component as expected, you can set the Aura component to Salesforce API version 39.0, which disables Lightning Locker for the component. See Disable Lightning Locker for a Component in the Lightning Aura Components Developer Guide.
For consistency and ease of debugging, avoid having a parent Aura component and a child component on different API versions. Therefore, don’t use any Aura component set to API version 39.0 in a component hierarchy, such as a component within a component or a component that’s extending another component.
If LWS is enabled in the org, setting API version 39.0 in the component doesn’t disable LWS for the component. However, LWS is likely to allow behaviors of components that Lightning Locker blocks, removing the need to disable it.
Turn Off Lightning Locker
If you turn off Lightning Locker in your site, you disable it for all your site’s third-party components and custom code. The ramifications can be far-ranging and unexpected, such as introducing security flaws into your site. And if a third-party component hasn’t been enabled to work without Lightning Locker, it can prevent that component from being available at design time and rendering at runtime. When Lightning Locker is turned off, components from different namespaces can interact with and access each other’s Document Object Model (DOM), and restrictions around custom resources interacting with your site are relaxed.
For more information on disabling Lightning Locker, see Select a Security Level in Experience Builder Sites in Salesforce Help.