From 4ff6e41877b9d0d4a3f6ddc1fc8ed9711c48a5ee Mon Sep 17 00:00:00 2001 From: Pavel Hurieiev Date: Wed, 6 Oct 2021 03:20:41 +0200 Subject: [PATCH] fix(rrweb-snapshot): don't exclude @import CSS rules from the output and use CSSRule.cssText instead when they throw an exception while accessing their CSSStyleSheet.cssRules property (#720) --- packages/rrweb-snapshot/src/snapshot.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/rrweb-snapshot/src/snapshot.ts b/packages/rrweb-snapshot/src/snapshot.ts index f2eccf5c..6f346e6e 100644 --- a/packages/rrweb-snapshot/src/snapshot.ts +++ b/packages/rrweb-snapshot/src/snapshot.ts @@ -49,9 +49,13 @@ function getCssRulesString(s: CSSStyleSheet): string | null { } function getCssRuleString(rule: CSSRule): string { - return isCSSImportRule(rule) - ? getCssRulesString(rule.styleSheet) || '' - : rule.cssText; + let cssStringified = rule.cssText; + if (isCSSImportRule(rule)) { + try { + cssStringified = getCssRulesString(rule.styleSheet) || cssStringified; + } catch {} + } + return cssStringified; } function isCSSImportRule(rule: CSSRule): rule is CSSImportRule {