From 042beb5820d923c75352fdce7e0c5878793eb76d Mon Sep 17 00:00:00 2001 From: Billy Vong Date: Fri, 6 Dec 2024 13:58:16 -0500 Subject: [PATCH] fix(snapshot): Change to ignore all `link[rel="modulepreload"]` ... removes requirement to have `as="script"` attribute. Also fixes prefetch to extract file extension instead of checking end of string since there can be URL parameters. --- packages/rrweb-snapshot/src/rebuild.ts | 12 ++++++++---- packages/rrweb-snapshot/src/snapshot.ts | 3 +-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/rrweb-snapshot/src/rebuild.ts b/packages/rrweb-snapshot/src/rebuild.ts index f92f0b2936..a2b096f1da 100644 --- a/packages/rrweb-snapshot/src/rebuild.ts +++ b/packages/rrweb-snapshot/src/rebuild.ts @@ -8,7 +8,12 @@ import { attributes, legacyAttributes, } from './types'; -import { isElement, Mirror, isNodeMetaEqual } from './utils'; +import { + isElement, + Mirror, + isNodeMetaEqual, + extractFileExtension, +} from './utils'; const tagMap: tagMap = { script: 'noscript', @@ -245,15 +250,14 @@ function buildNode( } else if ( tagName === 'link' && (n.attributes.rel === 'preload' || - n.attributes.rel === 'modulepreload') && - n.attributes.as === 'script' + n.attributes.rel === 'modulepreload') ) { // ignore } else if ( tagName === 'link' && n.attributes.rel === 'prefetch' && typeof n.attributes.href === 'string' && - n.attributes.href.endsWith('.js') + extractFileExtension(n.attributes.href) === 'js' ) { // ignore } else if ( diff --git a/packages/rrweb-snapshot/src/snapshot.ts b/packages/rrweb-snapshot/src/snapshot.ts index 1d26432c11..afff9eb495 100644 --- a/packages/rrweb-snapshot/src/snapshot.ts +++ b/packages/rrweb-snapshot/src/snapshot.ts @@ -1099,8 +1099,7 @@ function slimDOMExcluded( // (module)preload link (sn.tagName === 'link' && (sn.attributes.rel === 'preload' || - sn.attributes.rel === 'modulepreload') && - sn.attributes.as === 'script') || + sn.attributes.rel === 'modulepreload')) || // prefetch link (sn.tagName === 'link' && sn.attributes.rel === 'prefetch' &&