Skip to content

Commit

Permalink
Ensure the iframe id survives the onceIframeLoaded process; for som…
Browse files Browse the repository at this point in the history
…e reason I'm seeing the `__sn` attribute on the iframe DOM element disappearing with the callback
  • Loading branch information
eoghanmurray committed Apr 5, 2024
1 parent 3d1877c commit 8f887fa
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
5 changes: 5 additions & 0 deletions packages/rrweb-snapshot/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,7 @@ export function serializeNodeWithId(
onSerialize?: (n: Node) => unknown;
onIframeLoad?: (
iframeNode: HTMLIFrameElement,
iframeId: number,
node: serializedElementNodeWithId,
) => unknown;
iframeLoadTimeout?: number;
Expand Down Expand Up @@ -1131,6 +1132,7 @@ export function serializeNodeWithId(
serializedNode.type === NodeType.Element &&
serializedNode.tagName === 'iframe'
) {
const iframeId = serializedNode.id;
onceIframeLoaded(
n as HTMLIFrameElement,
() => {
Expand Down Expand Up @@ -1163,8 +1165,10 @@ export function serializeNodeWithId(
});

if (serializedIframeNode) {
// n may have lost it's __sn attribute by the time we get to this callback
onIframeLoad(
n as HTMLIFrameElement,
iframeId,
serializedIframeNode as serializedElementNodeWithId,
);
}
Expand Down Expand Up @@ -1249,6 +1253,7 @@ function snapshot(
onSerialize?: (n: Node) => unknown;
onIframeLoad?: (
iframeNode: HTMLIFrameElement,
iframeId: number,
node: serializedElementNodeWithId,
) => unknown;
iframeLoadTimeout?: number;
Expand Down
3 changes: 2 additions & 1 deletion packages/rrweb/src/record/iframe-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ export class IframeManager {

public attachIframe(
iframeEl: HTMLIFrameElement,
parentId: number,
childSn: serializedNodeWithId,
) {
this.mutationCb({
adds: [
{
parentId: this.mirror.getId(iframeEl),
parentId: parentId,
nextId: null,
node: childSn,
},
Expand Down
4 changes: 2 additions & 2 deletions packages/rrweb/src/record/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,8 @@ function record<T = eventWithTime>(
shadowDomManager.addShadowRoot(n.shadowRoot, document);
}
},
onIframeLoad: (iframe, childSn) => {
iframeManager.attachIframe(iframe, childSn);
onIframeLoad: (iframe, iframeid, childSn) => {
iframeManager.attachIframe(iframe, iframeid, childSn);
shadowDomManager.observeAttachShadow(iframe);
},
onStylesheetLoad: (linkEl, childSn) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/rrweb/src/record/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@ export default class MutationBuffer {
this.shadowDomManager.addShadowRoot(n.shadowRoot, this.doc);
}
},
onIframeLoad: (iframe, childSn) => {
this.iframeManager.attachIframe(iframe, childSn);
onIframeLoad: (iframe, iframeId, childSn) => {
this.iframeManager.attachIframe(iframe, iframeId, childSn);
this.shadowDomManager.observeAttachShadow(iframe);
},
onStylesheetLoad: (link, childSn) => {
Expand Down

0 comments on commit 8f887fa

Please sign in to comment.