Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check cssRules before css variables are read from stylesheet (again) #2580

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/app/shared/sass-helper/css-variable.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@
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 (cross-origin) styles might have no css rules value and throw some exception
try {
return styleSheet.cssRules;

Check warning on line 36 in src/app/shared/sass-helper/css-variable.service.ts

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L35 - L36 were not covered by tests
} catch (e) {
return false;

Check warning on line 38 in src/app/shared/sass-helper/css-variable.service.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L38 was not covered by tests
}
};

/*
Determine if the given rule is a CSSStyleRule
See: https://developer.mozilla.org/en-US/docs/Web/API/CSSRule#Type_constants
Expand Down Expand Up @@ -93,8 +106,10 @@
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(
Expand Down
Loading