From 81ff66674203e93c0d7e9671ac5b9593d2bfb0ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Risto=20Nyk=C3=A4nen?= Date: Tue, 7 Jan 2025 10:37:16 +0200 Subject: [PATCH] UHF-11208: wait for the cookies for a while instead of just preventing the chat from loading --- assets/js/chat_leijuke.js | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/assets/js/chat_leijuke.js b/assets/js/chat_leijuke.js index 1fa814f4d..d30cafe98 100644 --- a/assets/js/chat_leijuke.js +++ b/assets/js/chat_leijuke.js @@ -34,9 +34,29 @@ class EuCookieManager { cookieCheck(cookieNames) { let cookiesOk = true; - cookieNames.map((cookieName) => { - if (!Drupal.cookieConsent.getConsentStatus([cookieName])) cookiesOk = false; - }); + + // If cookies are not available yet, wait for a while. + if (Drupal.cookieConsent.getConsentStatus(cookieNames) === undefined) { + let i = 0; + + const interval = setInterval(()=> { + let found = false; + cookieNames.map((cookieName) => { + found = Drupal.cookieConsent.getConsentStatus([cookieName]) || false; + }); + + if (i >= 3 || found) { + cookiesOk = found; + clearInterval(interval); + } + i++; + }, 1000) + } else { + cookieNames.map((cookieName) => { + if (!Drupal.cookieConsent.getConsentStatus([cookieName])) cookiesOk = false; + }); + } + return cookiesOk; } cookieSet() {