Skip to content

Commit fa79c35

Browse files
Check cssRules before css variables are read from stylesheet (DSpace#2454)
Check cssRules existence before css variables are get from stylesheet
1 parent 5fd2782 commit fa79c35

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/app/shared/sass-helper/css-variable.service.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ export class CSSVariableService {
2626
return styleSheet.href.indexOf(window.location.origin) === 0;
2727
};
2828

29+
/**
30+
* Checks whether the specific stylesheet object has the property cssRules
31+
* @param styleSheet The stylesheet
32+
*/
33+
hasCssRules = (styleSheet) => {
34+
// Injected styles might have no css rules value
35+
return styleSheet.hasOwnProperty('cssRules') && styleSheet.cssRules;
36+
};
37+
2938
/*
3039
Determine if the given rule is a CSSStyleRule
3140
See: https://developer.mozilla.org/en-US/docs/Web/API/CSSRule#Type_constants
@@ -93,8 +102,10 @@ export class CSSVariableService {
93102
if (isNotEmpty(document.styleSheets)) {
94103
// styleSheets is array-like, so we convert it to an array.
95104
// Filter out any stylesheets not on this domain
105+
// Filter out any stylesheets that have no cssRules property
96106
return [...document.styleSheets]
97107
.filter(this.isSameDomain)
108+
.filter(this.hasCssRules)
98109
.reduce(
99110
(finalArr, sheet) =>
100111
finalArr.concat(

0 commit comments

Comments
 (0)