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 <laura.escamilla@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
Owen Leonard 2026-09-14 08:30:46 -04:00 committed by Pedro Amorim
parent 9e0b6c3914
commit 04314c4fbc
No known key found for this signature in database
GPG Key ID: 06B75BA7F3894D55
1 changed files with 3 additions and 2 deletions

View File

@ -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();
});