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 #2454

Merged
merged 2 commits into from
Oct 17, 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
11 changes: 11 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,15 @@ 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;
};

floriangantner marked this conversation as resolved.
Show resolved Hide resolved
/*
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 +102,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(
Expand Down
Loading