From c4a60abd650b7c0bb9c1ba3bf3ed6f6e6ed2d2ff Mon Sep 17 00:00:00 2001 From: "Gantner, Florian Klaus" Date: Wed, 23 Aug 2023 18:35:34 +0200 Subject: [PATCH 1/2] check cssRules existence before css variables are get from stylesheet (cherry picked from commit 367cda2de02f7524465dccc112438c57dce5cafe) --- src/app/shared/sass-helper/css-variable.service.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/app/shared/sass-helper/css-variable.service.ts b/src/app/shared/sass-helper/css-variable.service.ts index 0190a05036f..f5911737a0a 100644 --- a/src/app/shared/sass-helper/css-variable.service.ts +++ b/src/app/shared/sass-helper/css-variable.service.ts @@ -26,6 +26,17 @@ export class CSSVariableService { return styleSheet.href.indexOf(window.location.origin) === 0; }; + /** + * Checks whether the specific stylesheet object has the property cssRules + * @param styleSheet The stylesheet + */ + hasCssRules = (styleSheet) => { + // Injected styles might have no css rules value + return styleSheet.hasOwnProperty('cssRules') && styleSheet.cssRules; + }; + + + /* Determine if the given rule is a CSSStyleRule See: https://developer.mozilla.org/en-US/docs/Web/API/CSSRule#Type_constants @@ -93,8 +104,10 @@ export class CSSVariableService { if (isNotEmpty(document.styleSheets)) { // styleSheets is array-like, so we convert it to an array. // Filter out any stylesheets not on this domain + // Filter out any stylesheets that have no cssRules property return [...document.styleSheets] .filter(this.isSameDomain) + .filter(this.hasCssRules) .reduce( (finalArr, sheet) => finalArr.concat( From 21dcef0a42ebbc486f5d0afc8d72db312099a2d2 Mon Sep 17 00:00:00 2001 From: "Gantner, Florian Klaus" Date: Tue, 17 Oct 2023 14:32:22 +0200 Subject: [PATCH 2/2] checkstyle remove unused extra lines (cherry picked from commit 5f8a9dea34159fc1e7f067b1bbcb5dabc6bf4145) --- src/app/shared/sass-helper/css-variable.service.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/app/shared/sass-helper/css-variable.service.ts b/src/app/shared/sass-helper/css-variable.service.ts index f5911737a0a..ca6384e0ee5 100644 --- a/src/app/shared/sass-helper/css-variable.service.ts +++ b/src/app/shared/sass-helper/css-variable.service.ts @@ -35,8 +35,6 @@ export class CSSVariableService { return styleSheet.hasOwnProperty('cssRules') && styleSheet.cssRules; }; - - /* Determine if the given rule is a CSSStyleRule See: https://developer.mozilla.org/en-US/docs/Web/API/CSSRule#Type_constants