Enhance RocketChat livechat initialization with detailed logging
- Added console logs to track the initialization process of the RocketChat livechat widget, including the setting of the URL and script loading status. - Improved error handling by logging warnings when the script tag is not found or when the script fails to load. - Ensured that the script loads correctly based on the DOM readiness state, enhancing reliability and user experience.
This commit is contained in:
@@ -89,6 +89,8 @@ const { language, textDirection } = I18N;
|
||||
<script type="text/javascript">
|
||||
// Initialize RocketChat livechat widget with proper error handling
|
||||
(function(w, d, s, u) {
|
||||
console.log('RocketChat initialization started');
|
||||
|
||||
// Initialize RocketChat object if it doesn't exist
|
||||
w.RocketChat = function(c) {
|
||||
if (w.RocketChat._) {
|
||||
@@ -103,12 +105,17 @@ const { language, textDirection } = I18N;
|
||||
}
|
||||
|
||||
w.RocketChat.url = u;
|
||||
console.log('RocketChat URL set to:', u);
|
||||
|
||||
// Wait for DOM to be ready before loading the script
|
||||
function loadRocketChat() {
|
||||
try {
|
||||
console.log('Loading RocketChat script...');
|
||||
const h = d.getElementsByTagName(s)[0];
|
||||
if (!h) return;
|
||||
if (!h) {
|
||||
console.warn('No script tag found to insert before');
|
||||
return;
|
||||
}
|
||||
|
||||
const j = d.createElement(s);
|
||||
j.async = true;
|
||||
@@ -119,7 +126,12 @@ const { language, textDirection } = I18N;
|
||||
console.warn('RocketChat livechat script failed to load');
|
||||
};
|
||||
|
||||
j.onload = function() {
|
||||
console.log('RocketChat script loaded successfully');
|
||||
};
|
||||
|
||||
h.parentNode.insertBefore(j, h);
|
||||
console.log('RocketChat script tag inserted');
|
||||
} catch (error) {
|
||||
console.warn('Error loading RocketChat livechat:', error);
|
||||
}
|
||||
@@ -127,8 +139,10 @@ const { language, textDirection } = I18N;
|
||||
|
||||
// Load when DOM is ready
|
||||
if (d.readyState === 'loading') {
|
||||
console.log('DOM still loading, waiting for DOMContentLoaded');
|
||||
d.addEventListener('DOMContentLoaded', loadRocketChat);
|
||||
} else {
|
||||
console.log('DOM already loaded, loading RocketChat immediately');
|
||||
loadRocketChat();
|
||||
}
|
||||
})(window, document, 'script', 'https://chat.365devnet.eu/livechat');
|
||||
|
Reference in New Issue
Block a user