Chapter 1: LWC Tutorial – Lightning Locker and Lightning Locker Tools

Chapter 1: LWC Tutorial – Lightning Locker and Lightning Locker Tools

On September 26, 2022, Posted by , In LWC Tutorial, With Comments Off on Chapter 1: LWC Tutorial – Lightning Locker and 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)

Comments are closed.