Subscribing to plugin events break vanilla javascript and jQuery

I load my config file the standard way:

<script src="https://apps.mypurecloud.com/widgets/9.0/cxbus.min.js" 
	onload="javascript:CXBus.configure({debug:false,pluginsPath:'https://apps.mypurecloud.com/widgets/9.0/plugins/'}); 
		CXBus.loadFile('<%=request.getContextPath()%>/resources/js/GenesysCloudChat/GenesysChatConfig.js').done(function(){CXBus.loadPlugin('widgets-core')});">
</script>

My GenesysChatConfig.js file looks like so:

window._genesys = {
	widgets : {
		main : {
			theme : 'light',
			preload: ['webchat'],
		},
		webchat : {
			actionsMenu : true,
			uploadsEnabled : true,
			confirmFormCloseEnabled : true,
			charCountEnabled : true,
			chatButton: {
		    	enabled: false
		    },
			transport : {
				type : 'purecloud-v2-sockets',
				dataURL : 'https://api.mypurecloud.com',
				deploymentKey : [KEY_HERE],
				orgGuid : [ORG_GUID_HERE],
				interactionData : {
					routing : {
						targetType : 'QUEUE',
						targetAddress : [CHAT_QUEUE_NAME_HERE],
						priority : 2
					}
				}
			},
		},
	}
};

However, if I add the following code to my GenesysChatConfig.js (or call this code outside of this .js file, even):

const chatPlugin = CXBus.registerPlugin('Custom');

chatPlugin.subscribe('WebChatService.ready', function (e) {
  console.log('Chat ready', e);
});

then the jQuery that runs my ui-datepicker-trigger from the jQuery library (jquery-ui-1.8.6.custom.min.js) stops functioning completely. No errors are thrown when I try to click on the datepicker, it's just completely unresponsive. I see this behavior consistently and if I remove the "subscribe" code, it works okay (creating the "chatPlugin" is fine). This happens on any and every subscribe event (WebChatService, Overlay, Toaster, WindowManager, etc.).

Any help would be greatly appreciated, thank you!
Colton

This is also impacting my pure JavaScript. For example, I can add an event listener to one of my elements, but as soon as I do one subscription, the event listener stops working. If I re-add the event listener, it starts working again.
Example of event listener on my page:

let myElement = document.getElementById('myButton');

 myElement.addEventListener("click", function() {
    this.classList.toggle("active");
 });

Hi @Colton_Young

Subscribing to plugin doesn't break anything like this. CXBus subscription callbacks are scoped only to CXBus. Infact, our test page https://apps.mypurecloud.com/widgets/9.0/launcher.html is using vanilla javascript for listening to button clicks and it also runs Widgets.

Are you seeing any errors in your browser console? If CXBus is not yet loaded you are trying to access it, that could be the case where it's resulting in an error and stop executing at that point, resulting in your native script not executed.

If thats the case, we have an onReady() API that you might have to look at and move subscribing to events inside that function, in this way it gets executed only after Widgets is loaded resulting in everything to work properly.

https://all.docs.genesys.com/WID/Current/SDK/App-combined#config

Thank you Ranjith for your response.

We have moved our code into the onReady API and adjusted some issues caused by using
document.body.innerHTML
for inserting our visual components for chat.

This seems to have solved the issue. Thank you for your assistance!

Colton

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.