Skip to content

Commit

Permalink
fix(snapshot): Change to ignore all link[rel="modulepreload"] (#228)
Browse files Browse the repository at this point in the history
... 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.
  • Loading branch information
billyvg authored Dec 10, 2024
1 parent ba5a067 commit 81d8462
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
12 changes: 8 additions & 4 deletions packages/rrweb-snapshot/src/rebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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 (
Expand Down
3 changes: 1 addition & 2 deletions packages/rrweb-snapshot/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1100,8 +1100,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' &&
Expand Down

0 comments on commit 81d8462

Please sign in to comment.