Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .changeset/shiny-socks-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'rrweb-snapshot': patch
---

Fix inline stylesheet capture on WebKit by reading CSS rules from `HTMLLinkElement.sheet` before falling back to `document.styleSheets`.
12 changes: 8 additions & 4 deletions packages/rrweb-snapshot/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -587,10 +587,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;
});
// Try the element's .sheet first (works on WebKit even when
// document.styleSheets hasn't been updated yet), then fall back
// to searching document.styleSheets by href.
const stylesheet =
(n as HTMLLinkElement).sheet ||
Array.from(doc.styleSheets).find((s) => {
return s.href === (n as HTMLLinkElement).href;
});
let cssText: string | null = null;
if (stylesheet) {
cssText = stringifyStylesheet(stylesheet);
Expand Down
Loading