---
schema_version: "1"
id: 423a103127a116124a6e136a66b6a0b843de386f39f0c8c1bc0781feb326fa23
title: Third-Party Library Considerations for Lightning Web Security
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/lwc/lightning-components-security/guides/lws/lws-js.md
canonical_url: https://developer.salesforce.com/docs/platform/lightning-components-security/guide/lws-js.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 8f0bf1c8a1b2e6f5f4701f96be6cda66f339a21497b30e5fec0f190ee8cd4156
products:
  - Security for Lightning Components
  - lwc
---
# Third-Party Library Considerations for Lightning Web Security

Third-party scripts can encounter issues when running with Lightning Web Security (LWS) enabled if they have these behaviors.

## Third-Party Library Sets Up on Global `window` Object

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 `window` object.

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 `self` to `global`.

```javascript
(function (global) {
  global = global || self;
  global.myFunction = function () {};
})(this);
```

In this code, `this` is passed to the closure function as `global`. With LWS, `this` and `global` are undefined, so this code makes sure that `global` evaluates as the sandbox `global`.

## Third-Party Library Sets Strict Mode

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.

For example, errors occur if the script attempts to set something in the global object. LWS implicitly enforces most strict mode restrictions, but allows writing to virtual global objects in its JavaScript sandboxes. Setting strict mode explicitly in code interferes with LWS.

The workaround is to remove `"use strict"` in the third-party script.

Alternatively, modify the third-party code to assign `self` to `global` as shown in the [Third-Party Library Sets Up on Global `window` Object](#third-party-library-sets-up-on-global-window-object) section.

:::Note

If you’ve addressed these issues and the library still isn’t compliant, ask the library maintainers to update the code to comply with LWS, or, if the project is open-source, contribute the changes yourself. Another option is to fork the repository, make the changes, and build your own version of the library. It’s your responsibility to make sure any third-party libraries work with your Lightning components before deployment.

:::
