Skip to content

Commit e1e2941

Browse files
authored
Merge pull request DSpace#2580 from uniba-ub/issue2450-cssrules-exception
Check cssRules before css variables are read from stylesheet (again)
2 parents ab17164 + 4dd334f commit e1e2941

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ 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 (cross-origin) styles might have no css rules value and throw some exception
35+
try {
36+
return styleSheet.cssRules;
37+
} catch (e) {
38+
return false;
39+
}
40+
};
41+
2942
/*
3043
Determine if the given rule is a CSSStyleRule
3144
See: https://developer.mozilla.org/en-US/docs/Web/API/CSSRule#Type_constants
@@ -93,8 +106,10 @@ export class CSSVariableService {
93106
if (isNotEmpty(document.styleSheets)) {
94107
// styleSheets is array-like, so we convert it to an array.
95108
// Filter out any stylesheets not on this domain
109+
// Filter out any stylesheets that have no cssRules property
96110
return [...document.styleSheets]
97111
.filter(this.isSameDomain)
112+
.filter(this.hasCssRules)
98113
.reduce(
99114
(finalArr, sheet) =>
100115
finalArr.concat(

0 commit comments

Comments
 (0)