[SalesForce] ny way to validate a third party JavaScript library against Lightning LockerService

I have been using some of the third party libraries e.g. pdf.js and html2canvas.js for a customer project. Now when I activate the LockerService, these libraries do not work as expected. Is there any way to validate these third party libraries against Lightning LockerService?

I know there is one utility from Salesforce called Lightning CLI but i guess it supports only lightning component JavaScript code only not the third party libraries.

Best Answer

Unfortunately, there is no silver bullet to know if a library is 100% LockerService compliant or not. The easiest thing to do is to create a small sample app and test the library out yourself. This will at least verify the library loads without error and you can call basic functionality.

Here are some common violations I see libraries making that cause the library not to work with LockerService enabled that you can try to manually check yourself:

  • Must explicitly attach library global to window rather than trying to declare a variable that becomes global. More info.
  • CSP violations. Scan code for any usages of eval, new Function(), or <script> tags.
  • DOM access. Libraries that attempt to do broad scans of the DOM rather than only manipulating elements passed to their APIs may be blocked. You should only be manipulating DOM your own namespace created.
  • Use of non-standard or unsupported DOM/BOM APIs. See this app for what's exposed inside LockerService.

More details about Locker rules here.

Related Topic