Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/rrweb/src/record/iframe-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,5 +333,8 @@ export class IframeManager {
contentWindow.removeEventListener('message', handler);
});
this.nestedIframeListeners.clear();

this.crossOriginIframeMirror.reset();
this.crossOriginIframeStyleMirror.reset();
}
}
1 change: 1 addition & 0 deletions packages/rrweb/src/record/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@
plugins
?.filter((p) => p.observer)
?.map((p) => ({
observer: p.observer!,

Check warning on line 560 in packages/rrweb/src/record/index.ts

View workflow job for this annotation

GitHub Actions / ESLint Check and Report Upload

Forbidden non-null assertion
options: p.options,
callback: (payload: object) =>
wrappedEmit({
Expand All @@ -575,7 +575,7 @@

const loadListener = (iframeEl: HTMLIFrameElement) => {
try {
handlers.push(observe(iframeEl.contentDocument!));

Check warning on line 578 in packages/rrweb/src/record/index.ts

View workflow job for this annotation

GitHub Actions / ESLint Check and Report Upload

Forbidden non-null assertion
} catch (error) {
// TODO: handle internal error
console.warn(error);
Expand Down Expand Up @@ -622,6 +622,7 @@
processedNodeManager.destroy();
iframeManager.removeLoadListener();
iframeManager.destroy();
mirror.reset();
recording = false;
unregisterErrorHandler();
};
Expand Down
6 changes: 6 additions & 0 deletions packages/rrweb/src/record/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,12 @@ export default class MutationBuffer {
this.canvasManager.reset();
}

public destroy() {
while (this.mapRemoves.length) {
this.mirror.removeNodeFromMap(this.mapRemoves.shift()!);
}
}

public processMutations = (mutations: mutationRecord[]) => {
mutations.forEach(this.processMutation); // adds mutations to the buffer
this.emit(); // clears buffer if not locked/frozen
Expand Down
1 change: 1 addition & 0 deletions packages/rrweb/src/record/observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,7 @@ export function initObservers(
}

return callbackWrapper(() => {
mutationBuffers.forEach((b) => b.destroy());
mutationBuffers.forEach((b) => b.reset());
mutationObserver?.disconnect();
mousemoveHandler();
Expand Down
22 changes: 18 additions & 4 deletions packages/rrweb/src/record/observers/canvas/canvas-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,20 @@ export class CanvasManager {
private resetObservers?: listenerHandler;
private frozen = false;
private locked = false;
private rafIdTimestamp: number | null = null;
private rafIdFlush: number | null = null;

public reset() {
this.pendingCanvasMutations.clear();
this.resetObservers && this.resetObservers();
if (this.rafIdTimestamp !== null) {
cancelAnimationFrame(this.rafIdTimestamp);
this.rafIdTimestamp = null;
}
if (this.rafIdFlush !== null) {
cancelAnimationFrame(this.rafIdFlush);
this.rafIdFlush = null;
}
}

public freeze() {
Expand Down Expand Up @@ -296,15 +306,17 @@ export class CanvasManager {
}

private startPendingCanvasMutationFlusher() {
requestAnimationFrame(() => this.flushPendingCanvasMutations());
this.rafIdFlush = requestAnimationFrame(() =>
this.flushPendingCanvasMutations(),
);
}

private startRAFTimestamping() {
const setLatestRAFTimestamp = (timestamp: DOMHighResTimeStamp) => {
this.rafStamps.latestId = timestamp;
requestAnimationFrame(setLatestRAFTimestamp);
this.rafIdTimestamp = requestAnimationFrame(setLatestRAFTimestamp);
};
requestAnimationFrame(setLatestRAFTimestamp);
this.rafIdTimestamp = requestAnimationFrame(setLatestRAFTimestamp);
}

flushPendingCanvasMutations() {
Expand All @@ -314,7 +326,9 @@ export class CanvasManager {
this.flushPendingCanvasMutationFor(canvas, id);
},
);
requestAnimationFrame(() => this.flushPendingCanvasMutations());
this.rafIdFlush = requestAnimationFrame(() =>
this.flushPendingCanvasMutations(),
);
}

flushPendingCanvasMutationFor(canvas: HTMLCanvasElement, id: number) {
Expand Down
Loading