Skip to content

Commit

Permalink
Merge pull request #6 from pendo-io/x-origin-frame
Browse files Browse the repository at this point in the history
cross origin frame bug fixes
  • Loading branch information
colingm authored Sep 27, 2023
2 parents 04fa0dd + 0458e37 commit 718539c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/rrweb/src/record/iframe-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class IframeManager {
private mirror: Mirror;
private mutationCb: mutationCallBack;
private wrappedEmit: (e: eventWithTime, isCheckout?: boolean) => void;
private takeFullSnapshot: (isCheckout?: boolean) => void;
private loadListener?: (iframeEl: HTMLIFrameElement) => unknown;
private stylesheetManager: StylesheetManager;
private recordCrossOriginIframes: boolean;
Expand All @@ -27,9 +28,11 @@ export class IframeManager {
stylesheetManager: StylesheetManager;
recordCrossOriginIframes: boolean;
wrappedEmit: (e: eventWithTime, isCheckout?: boolean) => void;
takeFullSnapshot: (isCheckout?: boolean) => void;
}) {
this.mutationCb = options.mutationCb;
this.wrappedEmit = options.wrappedEmit;
this.takeFullSnapshot = options.takeFullSnapshot;
this.stylesheetManager = options.stylesheetManager;
this.recordCrossOriginIframes = options.recordCrossOriginIframes;
this.crossOriginIframeStyleMirror = new CrossOriginIframeMirror(
Expand All @@ -47,6 +50,16 @@ export class IframeManager {
this.iframes.set(iframeEl, true);
if (iframeEl.contentWindow)
this.crossOriginIframeMap.set(iframeEl.contentWindow, iframeEl);

if (!iframeEl.contentDocument && iframeEl.contentWindow)
iframeEl.contentWindow.postMessage(
{
type: 'rrweb',
origin: window.location.origin,
snapshot: true,
},
'*',
);
}

public addLoadListener(cb: (iframeEl: HTMLIFrameElement) => unknown) {
Expand Down Expand Up @@ -94,6 +107,15 @@ export class IframeManager {
const iframeSourceWindow = message.source;
if (!iframeSourceWindow) return;

if (
iframeSourceWindow == window.parent &&
window != window.parent &&
message.data.snapshot
) {
this.takeFullSnapshot();
return;
}

const iframeEl = this.crossOriginIframeMap.get(message.source);
if (!iframeEl) return;

Expand Down
1 change: 1 addition & 0 deletions packages/rrweb/src/record/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ function record<T = eventWithTime>(
stylesheetManager: stylesheetManager,
recordCrossOriginIframes,
wrappedEmit,
takeFullSnapshot,
});

/**
Expand Down

0 comments on commit 718539c

Please sign in to comment.