2

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.

  • I think, the initial step that should be done is to check whether those libraries are JavaScript strict mode compliant. – SE_User Mar 16 '17 at 6:13
  • @SE_User, Yes I do take follow up with the author about ECMA strict mode and CSP but it take time to get any confirmation therefore wanted to check for any existing tool which could help me not only in pointing the errors but also giving the suggestions. – LakhanP Mar 16 '17 at 7:28
  • @SE_User, sometime author tell us that it is a known issue (e.g. one of the CSP directive constraint) then we don't have any choice other than writing our own library. – LakhanP Mar 16 '17 at 7:48
3

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.