From 6a2aedcce3bee48fe3f2878d39184792d81d7ff7 Mon Sep 17 00:00:00 2001 From: navaneethsdk Date: Tue, 9 Jan 2024 10:08:36 +0530 Subject: [PATCH 1/4] Fixes protocol URL regex --- packages/rrweb-snapshot/src/snapshot.ts | 77 ++++++++++++------------- 1 file changed, 38 insertions(+), 39 deletions(-) diff --git a/packages/rrweb-snapshot/src/snapshot.ts b/packages/rrweb-snapshot/src/snapshot.ts index 301f84430e..407a4a7196 100644 --- a/packages/rrweb-snapshot/src/snapshot.ts +++ b/packages/rrweb-snapshot/src/snapshot.ts @@ -66,7 +66,7 @@ let canvasService: HTMLCanvasElement | null; let canvasCtx: CanvasRenderingContext2D | null; const URL_IN_CSS_REF = /url\((?:(')([^']*)'|(")(.*?)"|([^)]*))\)/gm; -const URL_PROTOCOL_MATCH = /^(?:[a-z+]+:)?\/\//i; +const URL_PROTOCOL_MATCH = /^(?:[a-z+-]+:)?\/\//i; const URL_WWW_MATCH = /^www\..*/i; const DATA_URI = /^(data:)([^,]*),(.*)/i; export function absoluteToStylesheet( @@ -95,9 +95,8 @@ export function absoluteToStylesheet( return `url(${maybeQuote}${filePath}${maybeQuote})`; } if (filePath[0] === '/') { - return `url(${maybeQuote}${ - extractOrigin(href) + filePath - }${maybeQuote})`; + return `url(${maybeQuote}${extractOrigin(href) + filePath + }${maybeQuote})`; } const stack = href.split('/'); const parts = filePath.split('/'); @@ -269,7 +268,7 @@ export function _isBlockedElement( return true; } } else { - for (let eIndex = element.classList.length; eIndex--; ) { + for (let eIndex = element.classList.length; eIndex--;) { const className = element.classList[eIndex]; if (blockClass.test(className)) { return true; @@ -297,7 +296,7 @@ export function classMatchesRegex( return classMatchesRegex(node.parentNode, regex, checkAncestors); } - for (let eIndex = (node as HTMLElement).classList.length; eIndex--; ) { + for (let eIndex = (node as HTMLElement).classList.length; eIndex--;) { const className = (node as HTMLElement).classList[eIndex]; if (regex.test(className)) { return true; @@ -1280,46 +1279,46 @@ function snapshot( const maskInputOptions: MaskInputOptions = maskAllInputs === true ? { - color: true, - date: true, - 'datetime-local': true, - email: true, - month: true, - number: true, - range: true, - search: true, - tel: true, - text: true, - time: true, - url: true, - week: true, - textarea: true, - select: true, - password: true, - } + color: true, + date: true, + 'datetime-local': true, + email: true, + month: true, + number: true, + range: true, + search: true, + tel: true, + text: true, + time: true, + url: true, + week: true, + textarea: true, + select: true, + password: true, + } : maskAllInputs === false - ? { + ? { password: true, } - : maskAllInputs; + : maskAllInputs; const slimDOMOptions: SlimDOMOptions = slimDOM === true || slimDOM === 'all' ? // if true: set of sensible options that should not throw away any information - { - script: true, - comment: true, - headFavicon: true, - headWhitespace: true, - headMetaDescKeywords: slimDOM === 'all', // destructive - headMetaSocial: true, - headMetaRobots: true, - headMetaHttpEquiv: true, - headMetaAuthorship: true, - headMetaVerification: true, - } + { + script: true, + comment: true, + headFavicon: true, + headWhitespace: true, + headMetaDescKeywords: slimDOM === 'all', // destructive + headMetaSocial: true, + headMetaRobots: true, + headMetaHttpEquiv: true, + headMetaAuthorship: true, + headMetaVerification: true, + } : slimDOM === false - ? {} - : slimDOM; + ? {} + : slimDOM; return serializeNodeWithId(n, { doc: n, mirror, From 57dedf45e356c85a816bec55f84de2004a733b54 Mon Sep 17 00:00:00 2001 From: navaneethsdk Date: Tue, 9 Jan 2024 10:20:31 +0530 Subject: [PATCH 2/4] Reverting format changes --- packages/rrweb-snapshot/src/snapshot.ts | 75 +++++++++++++------------ 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/packages/rrweb-snapshot/src/snapshot.ts b/packages/rrweb-snapshot/src/snapshot.ts index 407a4a7196..b704531551 100644 --- a/packages/rrweb-snapshot/src/snapshot.ts +++ b/packages/rrweb-snapshot/src/snapshot.ts @@ -95,8 +95,9 @@ export function absoluteToStylesheet( return `url(${maybeQuote}${filePath}${maybeQuote})`; } if (filePath[0] === '/') { - return `url(${maybeQuote}${extractOrigin(href) + filePath - }${maybeQuote})`; + return `url(${maybeQuote}${ + extractOrigin(href) + filePath + }${maybeQuote})`; } const stack = href.split('/'); const parts = filePath.split('/'); @@ -268,7 +269,7 @@ export function _isBlockedElement( return true; } } else { - for (let eIndex = element.classList.length; eIndex--;) { + for (let eIndex = element.classList.length; eIndex--; ) { const className = element.classList[eIndex]; if (blockClass.test(className)) { return true; @@ -296,7 +297,7 @@ export function classMatchesRegex( return classMatchesRegex(node.parentNode, regex, checkAncestors); } - for (let eIndex = (node as HTMLElement).classList.length; eIndex--;) { + for (let eIndex = (node as HTMLElement).classList.length; eIndex--; ) { const className = (node as HTMLElement).classList[eIndex]; if (regex.test(className)) { return true; @@ -1279,46 +1280,46 @@ function snapshot( const maskInputOptions: MaskInputOptions = maskAllInputs === true ? { - color: true, - date: true, - 'datetime-local': true, - email: true, - month: true, - number: true, - range: true, - search: true, - tel: true, - text: true, - time: true, - url: true, - week: true, - textarea: true, - select: true, - password: true, - } + color: true, + date: true, + 'datetime-local': true, + email: true, + month: true, + number: true, + range: true, + search: true, + tel: true, + text: true, + time: true, + url: true, + week: true, + textarea: true, + select: true, + password: true, + } : maskAllInputs === false - ? { + ? { password: true, } - : maskAllInputs; + : maskAllInputs; const slimDOMOptions: SlimDOMOptions = slimDOM === true || slimDOM === 'all' ? // if true: set of sensible options that should not throw away any information - { - script: true, - comment: true, - headFavicon: true, - headWhitespace: true, - headMetaDescKeywords: slimDOM === 'all', // destructive - headMetaSocial: true, - headMetaRobots: true, - headMetaHttpEquiv: true, - headMetaAuthorship: true, - headMetaVerification: true, - } + { + script: true, + comment: true, + headFavicon: true, + headWhitespace: true, + headMetaDescKeywords: slimDOM === 'all', // destructive + headMetaSocial: true, + headMetaRobots: true, + headMetaHttpEquiv: true, + headMetaAuthorship: true, + headMetaVerification: true, + } : slimDOM === false - ? {} - : slimDOM; + ? {} + : slimDOM; return serializeNodeWithId(n, { doc: n, mirror, From 1e3421e04b9b20540774517abddf34fe743875d2 Mon Sep 17 00:00:00 2001 From: Justin Halsall Date: Fri, 2 Feb 2024 12:01:45 +0100 Subject: [PATCH 3/4] Create chilly-wombats-hide.md --- .changeset/chilly-wombats-hide.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/chilly-wombats-hide.md diff --git a/.changeset/chilly-wombats-hide.md b/.changeset/chilly-wombats-hide.md new file mode 100644 index 0000000000..ae39e52360 --- /dev/null +++ b/.changeset/chilly-wombats-hide.md @@ -0,0 +1,5 @@ +--- +"rrweb-snapshot": patch +--- + +Add support for chrome-extension://... urls in stylesheets From 826e76132331b8270dc1b816e7b1de755db7191e Mon Sep 17 00:00:00 2001 From: Justin Halsall Date: Mon, 12 Feb 2024 18:21:17 +0100 Subject: [PATCH 4/4] Update chilly-wombats-hide.md