From d61237e4e547b664f7c920e5ccbcc72e22b832f9 Mon Sep 17 00:00:00 2001 From: Eoghan Murray Date: Thu, 16 May 2024 00:15:17 +0100 Subject: [PATCH] WIP: An oddity in that it has a .sheet in the mutation , before the load event ... what if the load event has already fired in some browsers (or if the mutation event is delayed) --- packages/rrweb/src/record/mutation.ts | 5 +++++ packages/rrweb/src/record/stylesheet-manager.ts | 2 ++ 2 files changed, 7 insertions(+) diff --git a/packages/rrweb/src/record/mutation.ts b/packages/rrweb/src/record/mutation.ts index 6e95681ad2..2d3a634862 100644 --- a/packages/rrweb/src/record/mutation.ts +++ b/packages/rrweb/src/record/mutation.ts @@ -669,6 +669,11 @@ export default class MutationBuffer { value.toLowerCase() === 'stylesheet' && m.target.tagName === 'LINK' ) { + if (m.target.sheet) { + console.warn( + 'have we missed the onload event due to delayed mutation?', + ); + } this.stylesheetManager.trackLinkElement( m.target as HTMLLinkElement, ); diff --git a/packages/rrweb/src/record/stylesheet-manager.ts b/packages/rrweb/src/record/stylesheet-manager.ts index 654dabadc2..7a55ba342f 100644 --- a/packages/rrweb/src/record/stylesheet-manager.ts +++ b/packages/rrweb/src/record/stylesheet-manager.ts @@ -70,6 +70,7 @@ export class StylesheetManager { // if is already loaded, it will have .sheet available and that // will get serialized in the snapshot. The following is for when that doesn't happen linkEl.addEventListener('load', () => { + console.log('load'); if (!linkEl.sheet) { return; } @@ -80,6 +81,7 @@ export class StylesheetManager { } let _cssText = stringifyStylesheet(linkEl.sheet); if (_cssText) { + console.log('load emit'); _cssText = absoluteToStylesheet( _cssText, getHref(linkEl.ownerDocument),