Skip to content

Commit

Permalink
Fixes issue when cssRules are inaccessilbe (#384)
Browse files Browse the repository at this point in the history
When cssRules are inaccessible in a style sheet, getCSSRules
will throw an exception trying to read them, and then the
catch handler will fetch the css. But, when it goes to
insert the rule, it has a bug where it uses sheet.cssRules.length,
which causes an exception again and the rules are lost.

This results in the error:

Error inlining remote css file SecurityError: Failed to read the 'cssRules' property from 'CSSStyleSheet': Cannot access rules

This is referenced in a few issues such as issue #49.
  • Loading branch information
dancrevier authored Feb 13, 2025
1 parent f7837ce commit cb65be0
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/embed-webfonts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ async function getCSSRules(
.then((metadata) => embedFonts(metadata, options))
.then((cssText) =>
parseCSS(cssText).forEach((rule) => {
inline.insertRule(rule, sheet.cssRules.length)
inline.insertRule(rule, inline.cssRules.length)
}),
)
.catch((err: unknown) => {
Expand Down

0 comments on commit cb65be0

Please sign in to comment.