Live Agent in Lightning Communities with Locker Service?
I have been trying to implement Salesforce Live Agent within a Lightning Community Component. Before enabling Lightning Locker Service, the implementation was working perfectly. I placed the hosted deployment.js file in the Header Markup of the Community Builder and created a simple Lightning Component to display online/offline Live Agent buttons. The component’s controller handled initialization of Live Agent and starting chats when users clicked the buttons.
Here is a simplified version of the component I used:
<aura:component implements="forceCommunity:availableForAllPageTypes">
<!-- Initialize the Live Agent -->
<aura:handler name="init" value="{!this}" action="{!c.init}" />
<div class="container-fluid">
<div class="row">
<div class="col-sm-4 col-md-4 msiBoxCol">
<a href="" id="liveagent_button_online" class="thumbnail msiBox1"
style="text-align:center;padding-bottom:2em;display:none;"
onclick="{!c.startChat}">
<div class="msi-img1" style="padding-top:20px;"></div>
<h3 class="msiSmall">Live Chat Online</h3>
</a>
<a href="" id="liveagent_button_offline" class="thumbnail msiBox1"
style="text-align:center;padding-bottom:2em;">
<div class="msi-img1" style="padding-top:20px;"></div>
<h3 class="msiSmall">Live Chat Offline</h3>
</a>
</div>
</div>
</div>
</aura:component>
The controller had two methods: one to initialize Live Agent (init) and another to start the chat (startChat):
({
init : function(component, event, helper) {
if (!window._laq) {
window._laq = [];
console.log('MM-LC++++ - !window._laq');
}
window._laq.push(function(){
liveagent.showWhenOnline('CHAT ID 123', document.getElementById('liveagent_button_online'));
liveagent.showWhenOffline('CHAT ID 123', document.getElementById('liveagent_button_offline'));
console.log('MM-LC++++ - window._laq.push');
});
liveagent.init('https://d.la1w1.salesforceliveagent.com/chat', 'CHAT BUTTON ID', 'ORG ID');
},
startChat : function(component, event, helper) {
liveagent.startChat('CHAT ID 123');
},
})
This implementation worked perfectly without Locker Service. However, after enabling Locker Service in our development environment, the component broke completely. The page returned an “Invalid Page” error. After debugging, I found that the line initializing Live Agent:
liveagent.init('https://d.la1w1.salesforceliveagent.com/chat', 'CHAT BUTTON ID', 'ORG ID');
was the one causing the page failure. Also, window._laq was undefined inside the Locker Service context, even though the same code worked in production without Locker Service.
Attempts to use ltng:require with deployment.js as a static resource also failed. Manually running window._laq = []; and liveagent.init in the console works, but I need this to run automatically when the page loads.
My questions are: Is it possible to implement Salesforce Live Agent in a Lightning Community with Locker Service enabled? Why does window._laq behave differently in Locker Service? If it cannot be fixed on our side, how can we work with Salesforce to resolve this issue?
Answer:
This is a known issue and is tracked under Salesforce bug W-3214759. Live Agent is blocked in Community Templates when Locker Service is enabled. The problem is not a bug in your code but a result of how Locker Service enforces component encapsulation and scope isolation.
Before Locker Service, you were including deployment.js globally in the page header. This works because all scripts share the global window scope. After Locker Service is enabled, components are required to be self-contained and declare all dependencies explicitly. Scripts bound to the global scope outside the component are invisible inside the component, which is why window._laq is undefined and liveagent.init fails.
Locker Service virtualizes the global window object for each component. That means window._laq exists in the actual global scope, but the component only sees a virtualized scope. This explains why manually running code in the console works but automatic initialization inside the component does not.
Currently, there is no way to fix this entirely on the client side with the existing Live Agent library, because it relies on being globally scoped. Salesforce is aware of the issue and is actively working to address it. If Locker Service activation would block critical functionality like Live Agent, Salesforce will adjust the activation schedule accordingly.
For future implementations, the recommended approach would be to:
- Wait for Salesforce to provide a version of the Live Agent library compatible with Locker Service.
- Avoid placing globally-scoped scripts in Community headers. Use
ltng:requireto load dependencies into the component scope once a compatible library is available. - Test initialization inside the component using the virtualized
windowobject provided by Locker Service.
This means that until Salesforce releases an update, Live Agent cannot be used in Lightning Communities with Locker Service enabled. Any workaround that tries to bypass the virtualized window scope would not be supported and may break in future updates.
Explanation of the Code:
The component defines two anchor tags for online/offline chat buttons. The init handler attempts to initialize the Live Agent library and register the buttons with window._laq.push.
window._laq is used to queue Live Agent initialization functions until the library has loaded. liveagent.init initializes the connection to Salesforce Live Agent, and liveagent.startChat opens a chat session when the user clicks the button.
Locker Service blocks global script access, which breaks this initialization. Any references to window._laq or liveagent must exist inside the component’s virtualized scope. Since deployment.js relies on global scope, it does not work under Locker Service, resulting in the “Invalid Page” error.
Enroll for Salesforce Training Designed for Career Building Success
Our Salesforce Course is structured to deliver an in-depth understanding of the Salesforce platform, equipping you with the necessary skills to excel in the CRM industry. The program covers essential modules such as Salesforce Admin, Developer, and AI, combining theoretical knowledge with practical application. Through real-world projects and assignments, you’ll gain the expertise to tackle complex business challenges confidently using Salesforce solutions. Our experienced instructors ensure you acquire both technical knowledge and industry insights to succeed in the Salesforce ecosystem.
In addition to technical skills, our Salesforce Training in Denver provides personalized guidance, certification support, and interview preparation to boost your career opportunities. You’ll benefit from extensive study materials, hands-on project experience, and continuous support throughout your journey. By the end of the course, you’ll be ready for certification exams and have the problem-solving skills that employers seek. Start your Salesforce career with us today and unlock limitless opportunities. Sign up for a Free Demo now!

