diff --git a/.changeset/short-hounds-confess.md b/.changeset/short-hounds-confess.md new file mode 100644 index 00000000..7cb8b0d5 --- /dev/null +++ b/.changeset/short-hounds-confess.md @@ -0,0 +1,6 @@ +--- +"rrweb-snapshot": patch +"rrweb": patch +--- + +Change to ignore all link[rel="modulepreload"] instead of including only those with `as="script"` diff --git a/packages/rrweb-snapshot/src/rebuild.ts b/packages/rrweb-snapshot/src/rebuild.ts index c755637b..692da2d2 100644 --- a/packages/rrweb-snapshot/src/rebuild.ts +++ b/packages/rrweb-snapshot/src/rebuild.ts @@ -7,7 +7,12 @@ import { type legacyAttributes, } from '@rrweb/types'; import { type tagMap, type BuildCache } from './types'; -import { isElement, Mirror, isNodeMetaEqual } from './utils'; +import { + isElement, + Mirror, + isNodeMetaEqual, + extractFileExtension, +} from './utils'; import postcss from 'postcss'; const tagMap: tagMap = { @@ -299,16 +304,15 @@ function buildNode( continue; } else if ( tagName === 'link' && - (n.attributes.rel === 'preload' || - n.attributes.rel === 'modulepreload') && - n.attributes.as === 'script' + ((n.attributes.rel === 'preload' && 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 0e8ec68b..8c29fa0d 100644 --- a/packages/rrweb-snapshot/src/snapshot.ts +++ b/packages/rrweb-snapshot/src/snapshot.ts @@ -819,9 +819,8 @@ function slimDOMExcluded( (sn.tagName === 'script' || // (module)preload link (sn.tagName === 'link' && - (sn.attributes.rel === 'preload' || - sn.attributes.rel === 'modulepreload') && - sn.attributes.as === 'script') || + ((sn.attributes.rel === 'preload' && sn.attributes.as === 'script') || + sn.attributes.rel === 'modulepreload')) || // prefetch link (sn.tagName === 'link' && sn.attributes.rel === 'prefetch' &&