File tree Expand file tree Collapse file tree 1 file changed +19
-3
lines changed
packages/rrweb/src/replay Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -620,12 +620,28 @@ export class Replayer {
620620 this . iframe . setAttribute ( 'sandbox' , attributes . join ( ' ' ) ) ;
621621
622622 // Apply CSP if configured
623- if ( this . config . csp ) {
624- this . iframe . setAttribute ( 'csp' , this . config . csp ) ;
625- }
623+ // (Do not set non-standard 'csp' attribute)
626624
627625 this . disableInteract ( ) ;
628626 this . wrapper . appendChild ( this . iframe ) ;
627+ // Inject CSP meta tag into iframe's document if configured
628+ if ( this . config . csp && this . iframe . contentDocument ) {
629+ const meta = this . iframe . contentDocument . createElement ( 'meta' ) ;
630+ meta . httpEquiv = 'Content-Security-Policy' ;
631+ meta . content = this . config . csp ;
632+ // Ensure head exists before appending
633+ if ( this . iframe . contentDocument . head ) {
634+ this . iframe . contentDocument . head . appendChild ( meta ) ;
635+ } else {
636+ // If head doesn't exist, create it and append
637+ const head = this . iframe . contentDocument . createElement ( 'head' ) ;
638+ head . appendChild ( meta ) ;
639+ this . iframe . contentDocument . documentElement . insertBefore (
640+ head ,
641+ this . iframe . contentDocument . body || null
642+ ) ;
643+ }
644+ }
629645 if ( this . iframe . contentWindow && this . iframe . contentDocument ) {
630646 smoothscrollPolyfill (
631647 this . iframe . contentWindow ,
You can’t perform that action at this time.
0 commit comments