diff --git a/packages/rrweb-snapshot/src/snapshot.ts b/packages/rrweb-snapshot/src/snapshot.ts index 11c19d67..dd18d5c6 100644 --- a/packages/rrweb-snapshot/src/snapshot.ts +++ b/packages/rrweb-snapshot/src/snapshot.ts @@ -540,6 +540,10 @@ function serializeTextNode( }; } +function findStylesheet(doc: Document, href: string) { + return Array.from(doc.styleSheets).find((s) => s.href === href); +} + function serializeElementNode( n: HTMLElement, options: { @@ -592,9 +596,14 @@ function serializeElementNode( // remote css if (tagName === 'link' && inlineStylesheet) { //TODO: maybe replace this `.styleSheets` with original one - const stylesheet = Array.from(doc.styleSheets).find((s) => { - return s.href === (n as HTMLLinkElement).href; - }); + const href = (n as HTMLLinkElement).href; + let stylesheet = findStylesheet(doc, href); + if (!stylesheet && href.includes('.css')) { + const rootDomain = window.location.origin; + const stylesheetPath = href.replace(window.location.href, ''); + const potentialStylesheetHref = rootDomain + '/' + stylesheetPath; + stylesheet = findStylesheet(doc, potentialStylesheetHref); + } let cssText: string | null = null; if (stylesheet) { cssText = stringifyStylesheet(stylesheet);