Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions packages/rrweb-snapshot/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
obfuscateText,
isNativeShadowDom,
getCssRulesString,
isElementSrcBlocked,
} from './utils';

let _id = 1;
Expand Down Expand Up @@ -815,16 +816,20 @@ function serializeElementNode(
}
}
// block element
if (needBlock || needMask || (tagName === 'img' && enableStrictPrivacy)) {
if (
needBlock ||
needMask ||
(enableStrictPrivacy && isElementSrcBlocked(tagName))
) {
const { width, height } = n.getBoundingClientRect();
attributes = {
class: attributes.class,
rr_width: `${width}px`,
rr_height: `${height}px`,
};
if (enableStrictPrivacy) {
needBlock = true;
}
}
if (enableStrictPrivacy && isElementSrcBlocked(tagName)) {
needBlock = true;
}
// iframe
if (tagName === 'iframe' && !keepIframeSrcFn(attributes.src as string)) {
Expand Down Expand Up @@ -1069,10 +1074,10 @@ export function serializeNodeWithId(
!!serializedNode.needMask;

/** Highlight Code Begin */
// Remove the image's src if enableStrictPrivacy.
if (strictPrivacy && serializedNode.tagName === 'img') {
// process enableStrictPrivacy obfuscation of non-text elements
if (strictPrivacy && isElementSrcBlocked(serializedNode.tagName)) {
const clone = n.cloneNode();
(clone as unknown as HTMLImageElement).src = '';
(clone as unknown as { src: string }).src = '';
mirror.add(clone, serializedNode);
}
/** Highlight Code End */
Expand Down
11 changes: 11 additions & 0 deletions packages/rrweb-snapshot/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,15 @@ export function obfuscateText(text: string): string {
.join(' ') || '';
return text;
}

// returns true if the tag name is an element type that should have its source blocked
export function isElementSrcBlocked(tagName: string): boolean {
return (
tagName === 'img' ||
tagName === 'video' ||
tagName === 'audio' ||
tagName === 'source'
);
}

/* End of Highlight Code */