Lightning Locker Tools in LWC

Lightning Locker Tools in LWC

On September 26, 2022, Posted by , In LWC Tutorial, With Comments Off on Lightning Locker Tools in LWC
Lightning Locker Tools

On top of standard restrictions applied via native web APIs, lightning lockers implement a few more restrictions for security purposes.

What are lightning locker features?

  • By default, a strict mode of JavaScript is enabled
  • Components can only access elements that are part of it’s DOM
  • Lightning locker restricts the use of global objects by wrapping them in a secure wrapper which is present in JavaScript for example
    • The window is wrapped as SecureWindow
    • Element is wrapped as SecureElement
    • The document is wrapped as SecureDocument
  • We can’t use third-party web components (Only allows you to use components in lightning or c namespace)
  • Locker blocks access to global objects like $A, Aura, they are blocked as they might cause cross framework dependencies

Lightning Locker Tools

Lightning Locker tools help you develop secure code that is compatible and runs efficiently with Lightning Locker.

Lightning Locker API Viewer

As we earlier noted lightning locker has wrapped all the JavaScript global objects in a secure wrapper, with this, we can check what all standard DOM APIs are supported within each of those wrappers.

For example, setTimeOut, alert, console, etc are supported inside the lightning locker while Element. attachShadow is not allowed (because the LWC framework takes care of attaching shadow DOM to element)

For those looking for Salesforce learning, CRS Info Solutions provides an extensive Salesforce training program designed to enhance your skills and career opportunities. Explore our job-oriented Salesforce training to gain practical, hands-on experience, real-time projects included. Our training covers all essential aspects of Salesforce, ensuring comprehensive learning, providing daily notes, interview questions, certification preparation and job prep guidance. Enroll for Free demo today!

Comments are closed.