From 04314c4fbc6f1966e96f150f5733a6577ae6a65e Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Mon, 14 Sep 2026 08:30:46 -0400 Subject: [PATCH] Bug 38948: Modal error on some pages: Can't access property "backdrop" This patch adds some checks to cookieconsent.js to avoid errors in the console: If we try to access 'document.getElementById("cookieConsentModal")' when the element doesn't exist there will be an error: 'Uncaught TypeError: can't access property "backdrop", this._config is undefined' The error can be seen in the browser console on the Circulation home page and the Tools home page when the CookieConsent preference is enabled. To test apply the patch and clear your browser cache if necessary. - Enable the CoookieConsent system preference. - Go to the Circulation home page. There should be no error in the console. - Clear your browser's local storage to forget your consent. - Go to the staff client home page. The cookie consent message should appear. Sponsored-by: Athens County Public Libraries Signed-off-by: Laura_Escamilla Signed-off-by: Jonathan Druart Signed-off-by: Pedro Amorim --- koha-tmpl/intranet-tmpl/prog/js/cookieconsent.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/cookieconsent.js b/koha-tmpl/intranet-tmpl/prog/js/cookieconsent.js index 834dc1fd62..a745658746 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/cookieconsent.js +++ b/koha-tmpl/intranet-tmpl/prog/js/cookieconsent.js @@ -11,7 +11,8 @@ // The consent bar may not be in the DOM if it is not being used const consentBar = $("#cookieConsentBar"); - if (!consentBar) { + const cookieConsentModalEl = document.getElementById("cookieConsentModal"); + if (!consentBar || !cookieConsentModalEl) { return; } @@ -34,7 +35,7 @@ // When the modal is opened, populate our state based on currently // selected values - const cookieConsentModalEl = document.getElementById("cookieConsentModal"); + cookieConsentModalEl.addEventListener("shown.bs.modal", () => { initialiseSelected(); });