Third-Party Library Considerations for LWS
Third-party scripts can encounter issues when running with LWS enabled if they have these behaviors.
Some third-party scripts expect to add themselves to the global
window object. LWS confines them to a sandbox where they access a virtual copy of the global
To ensure that the code runs in the global scope of the LWS sandbox instead of attempting to access the actual global scope, modify the script code to assign
In this code,
this is passed to the closure function as
global. With LWS,
global are undefined, so this code makes sure that
global evaluates as the sandbox
If a third-party library script explicitly sets
"use strict", the browser can throw errors when your components use the script while running in LWS.
The workaround is to remove
"use strict" in the third-party script.
Alternatively, modify the third-party code to assign
global as shown above.