6

Salesforce mentions a new feature, Privileged Script, as part of Summer 21:

With Privileged Script, third-party JavaScript libraries can access components in LWR sites. An LWR site encapsulates all of its elements in Shadow DOM, which prevents third-party libraries from interacting with the components. This script lets libraries, such as Google Analytics and Google Tag Manager, bypass Shadow DOM.

This does not tell me how to use the feature. I have checked in a Summer 21 sandbox, adding an LWC to an LWR Experience, but do not see anything related to "privileged script".

How do I use this feature?

4

I have checked with our Salesforce team that owns this feature and got an update that the public-facing document would be available on 19/05(Safe Harbor).

In the meantime, the tag to use would be

<x-oasis-script src="third_party_library.js"></x-oasis-script>

And you can import and export global variables with the imported-global-names and exported-global-names attributes. Hope this helps!

UPDATE:

Documentation is now available regarding this feature: https://developer.salesforce.com/docs/atlas.en-us.232.0.exp_cloud_lwr.meta/exp_cloud_lwr/advanced_privileged_script.htm

6
  • 1
    Thank you very much for following up, Swetha. Can this be used for scripts hosted outside Salesforce? Does this only work for LWR "Build your own" communities?
    – Rob
    May 14 at 9:24
  • 1
    To answer the second question: this doesn't seem to work for Aura (non-LWR) communities. (Which is consistent with the release docs).
    – Rob
    May 14 at 9:41
  • 1
    @Rob I’ll check and confirm
    – Swetha
    May 14 at 10:34
  • To answer your question, Yes, but the site would need to have Relaxed CSP enabled and the third-party host would have to be allowlisted (in Settings -> Security & Privacy). See articles 1,2
    – Swetha
    May 14 at 16:18
  • When I try and use this in vscode I get this error at deploy time, any ideas? LWC1512: Missing resource value for @salesforce/oasis Aug 3 at 5:52

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.