Skip to content

Commit

Permalink
⚡ Ignore modulepreload and prefetch in link tags
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickadam committed Jan 9, 2023
1 parent ac26b8d commit 30633b6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
20 changes: 20 additions & 0 deletions packages/rum/src/domain/record/privacy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,26 @@ describe('getNodeSelfPrivacyLevel', () => {
html: '<script class="dd-privacy-allow">',
expected: NodePrivacyLevel.ALLOW,
},
{
msg: 'is a link with rel=preload and as=script',
html: '<link rel="preload" crossorigins as="script">',
expected: NodePrivacyLevel.IGNORE,
},
{
msg: 'is a link with rel=modulepreload and as=script',
html: '<link rel="modulepreload" as="script">',
expected: NodePrivacyLevel.IGNORE,
},
{
msg: 'is a link with rel=prefetch and as=script',
html: '<link rel="prefetch" as="script">',
expected: NodePrivacyLevel.IGNORE,
},
{
msg: 'is a link with rel=stylesheet and a not expected as=script',
html: '<link rel="stylesheet" as="script">',
expected: undefined,
},

// Precedence
{
Expand Down
4 changes: 2 additions & 2 deletions packages/rum/src/domain/record/privacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ export function shouldIgnoreElement(element: Element): boolean {
if (element.nodeName === 'LINK') {
const relAttribute = getLowerCaseAttribute('rel')
return (
// Scripts
(relAttribute === 'preload' && getLowerCaseAttribute('as') === 'script') ||
// Link as script - Ignore only when rel=preload, modulepreload or prefetch
(/preload|prefetch/i.test(relAttribute) && getLowerCaseAttribute('as') === 'script') ||
// Favicons
relAttribute === 'shortcut icon' ||
relAttribute === 'icon'
Expand Down

0 comments on commit 30633b6

Please sign in to comment.