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:
2025-07-24 14:57:01 +02:00
parent b75422716b
commit b2fbe18214

View File

@@ -89,6 +89,8 @@ const { language, textDirection } = I18N;
<script type="text/javascript"> <script type="text/javascript">
// Initialize RocketChat livechat widget with proper error handling // Initialize RocketChat livechat widget with proper error handling
(function(w, d, s, u) { (function(w, d, s, u) {
console.log('RocketChat initialization started');
// Initialize RocketChat object if it doesn't exist // Initialize RocketChat object if it doesn't exist
w.RocketChat = function(c) { w.RocketChat = function(c) {
if (w.RocketChat._) { if (w.RocketChat._) {
@@ -103,12 +105,17 @@ const { language, textDirection } = I18N;
} }
w.RocketChat.url = u; w.RocketChat.url = u;
console.log('RocketChat URL set to:', u);
// Wait for DOM to be ready before loading the script // Wait for DOM to be ready before loading the script
function loadRocketChat() { function loadRocketChat() {
try { try {
console.log('Loading RocketChat script...');
const h = d.getElementsByTagName(s)[0]; 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); const j = d.createElement(s);
j.async = true; j.async = true;
@@ -119,7 +126,12 @@ const { language, textDirection } = I18N;
console.warn('RocketChat livechat script failed to load'); console.warn('RocketChat livechat script failed to load');
}; };
j.onload = function() {
console.log('RocketChat script loaded successfully');
};
h.parentNode.insertBefore(j, h); h.parentNode.insertBefore(j, h);
console.log('RocketChat script tag inserted');
} catch (error) { } catch (error) {
console.warn('Error loading RocketChat livechat:', error); console.warn('Error loading RocketChat livechat:', error);
} }
@@ -127,8 +139,10 @@ const { language, textDirection } = I18N;
// Load when DOM is ready // Load when DOM is ready
if (d.readyState === 'loading') { if (d.readyState === 'loading') {
console.log('DOM still loading, waiting for DOMContentLoaded');
d.addEventListener('DOMContentLoaded', loadRocketChat); d.addEventListener('DOMContentLoaded', loadRocketChat);
} else { } else {
console.log('DOM already loaded, loading RocketChat immediately');
loadRocketChat(); loadRocketChat();
} }
})(window, document, 'script', 'https://chat.365devnet.eu/livechat'); })(window, document, 'script', 'https://chat.365devnet.eu/livechat');