diff --git a/packages/rrweb/src/replay/index.ts b/packages/rrweb/src/replay/index.ts index 5f1101cc23..e2d5f4c35b 100644 --- a/packages/rrweb/src/replay/index.ts +++ b/packages/rrweb/src/replay/index.ts @@ -618,6 +618,12 @@ export class Replayer { // hide iframe before first meta event this.iframe.style.display = 'none'; this.iframe.setAttribute('sandbox', attributes.join(' ')); + + // Apply CSP if configured + if (this.config.csp) { + this.iframe.setAttribute('csp', this.config.csp); + } + this.disableInteract(); this.wrapper.appendChild(this.iframe); if (this.iframe.contentWindow && this.iframe.contentDocument) { @@ -1536,8 +1542,8 @@ export class Replayer { const targetDoc = mutation.node.rootId ? mirror.getNode(mutation.node.rootId) : this.usingVirtualDom - ? this.virtualDom - : this.iframe.contentDocument; + ? this.virtualDom + : this.iframe.contentDocument; if (isSerializedIframe(parent, mirror)) { this.attachDocumentToIframe( mutation, diff --git a/packages/rrweb/src/types.ts b/packages/rrweb/src/types.ts index a03e326b6f..d955589f1d 100644 --- a/packages/rrweb/src/types.ts +++ b/packages/rrweb/src/types.ts @@ -196,6 +196,7 @@ export type playerConfig = { warn: (...args: Parameters) => void; }; plugins?: ReplayPlugin[]; + csp?: string; }; export type missingNode = {