File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
packages/rrweb-snapshot/src Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -347,6 +347,14 @@ function onceIframeLoaded(
347
347
iframeEl . addEventListener ( 'load' , listener ) ;
348
348
}
349
349
350
+ function stringifyStyleSheet ( sheet : CSSStyleSheet ) : string {
351
+ return sheet . cssRules
352
+ ? Array . from ( sheet . cssRules )
353
+ . map ( ( rule ) => rule . cssText || '' )
354
+ . join ( '' )
355
+ : '' ;
356
+ }
357
+
350
358
function serializeNode (
351
359
n : Node ,
352
360
options : {
@@ -538,6 +546,16 @@ function serializeNode(
538
546
const isStyle = parentTagName === 'STYLE' ? true : undefined ;
539
547
const isScript = parentTagName === 'SCRIPT' ? true : undefined ;
540
548
if ( isStyle && textContent ) {
549
+ try {
550
+ // try to read style sheet
551
+ if ( ( n . parentNode as HTMLStyleElement ) . sheet ?. cssRules ) {
552
+ textContent = stringifyStyleSheet (
553
+ ( n . parentNode as HTMLStyleElement ) . sheet ! ,
554
+ ) ;
555
+ }
556
+ } catch {
557
+ // ignore error
558
+ }
541
559
textContent = absoluteToStylesheet ( textContent , getHref ( ) ) ;
542
560
}
543
561
if ( isScript ) {
You can’t perform that action at this time.
0 commit comments