Skip to content

Commit ec2a859

Browse files
Update packages/rrweb/src/replay/index.ts
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent cb29098 commit ec2a859

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

packages/rrweb/src/replay/index.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff 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,

0 commit comments

Comments
 (0)