Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Handle case where non imported stylesheet has relative urls that need…
… to be absolutified
  • Loading branch information
jeffdnguyen committed Jul 17, 2024
commit f4bfd7384ebc35e9b8085159e47b1c894476f6fd
24 changes: 18 additions & 6 deletions packages/rrweb-snapshot/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ export function stringifyStylesheet(s: CSSStyleSheet): string | null {
}

export function stringifyRule(rule: CSSRule, sheetHref: string | null): string {
let importStringified;
if (isCSSImportRule(rule)) {
let importStringified;
try {
importStringified =
// for same-origin stylesheets,
Expand All @@ -119,19 +119,31 @@ export function stringifyRule(rule: CSSRule, sheetHref: string | null): string {
// work around browser issues with the raw string `@import url(...)` statement
escapeImportStatement(rule);

if (sheetHref) {
importStringified = absolutifyURLs(importStringified, sheetHref);
if (rule.styleSheet.href) {
importStringified = absolutifyURLs(
importStringified,
rule.styleSheet.href,
);
}

return importStringified;
} catch (error) {
// ignore
}
} else if (isCSSStyleRule(rule) && rule.selectorText.includes(':')) {
}

let ruleStringified = rule.cssText;
if (isCSSStyleRule(rule) && rule.selectorText.includes(':')) {
// Safari does not escape selectors with : properly
// see https://bugs.webkit.org/show_bug.cgi?id=184604
return fixSafariColons(rule.cssText);
ruleStringified = fixSafariColons(ruleStringified);
}

if (sheetHref) {
return absolutifyURLs(ruleStringified, sheetHref);
}

return importStringified || rule.cssText;
return ruleStringified;
}

export function fixSafariColons(cssStringified: string): string {
Expand Down