Skip to content

Commit 5fc8029

Browse files
authored
fix: check for stylesheets on current domain too (#9)
1 parent 876e779 commit 5fc8029

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

packages/rrweb-snapshot/src/snapshot.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,10 @@ function serializeTextNode(
540540
};
541541
}
542542

543+
function findStylesheet(doc: Document, href: string) {
544+
return Array.from(doc.styleSheets).find((s) => s.href === href);
545+
}
546+
543547
function serializeElementNode(
544548
n: HTMLElement,
545549
options: {
@@ -592,9 +596,14 @@ function serializeElementNode(
592596
// remote css
593597
if (tagName === 'link' && inlineStylesheet) {
594598
//TODO: maybe replace this `.styleSheets` with original one
595-
const stylesheet = Array.from(doc.styleSheets).find((s) => {
596-
return s.href === (n as HTMLLinkElement).href;
597-
});
599+
const href = (n as HTMLLinkElement).href;
600+
let stylesheet = findStylesheet(doc, href);
601+
if (!stylesheet && href.includes('.css')) {
602+
const rootDomain = window.location.origin;
603+
const stylesheetPath = href.replace(window.location.href, '');
604+
const potentialStylesheetHref = rootDomain + '/' + stylesheetPath;
605+
stylesheet = findStylesheet(doc, potentialStylesheetHref);
606+
}
598607
let cssText: string | null = null;
599608
if (stylesheet) {
600609
cssText = stringifyStylesheet(stylesheet);

0 commit comments

Comments
 (0)