Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Resize and MediaInteraction events repeat generated after the iframe appeared #1251

Merged
merged 3 commits into from
Jul 7, 2023
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
5 changes: 5 additions & 0 deletions .changeset/nervous-buses-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'rrweb': patch
---

fix: Resize and MediaInteraction events repeat generated after the iframe appeared
24 changes: 14 additions & 10 deletions packages/rrweb/src/record/observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,10 @@ export function initScrollObserver({
return on('scroll', updatePosition, doc);
}

function initViewportResizeObserver({
viewportResizeCb,
}: observerParam): listenerHandler {
function initViewportResizeObserver(
{ viewportResizeCb }: observerParam,
{ win }: { win: IWindow },
): listenerHandler {
let lastH = -1;
let lastW = -1;
const updateDimension = callbackWrapper(
Expand All @@ -400,7 +401,7 @@ function initViewportResizeObserver({
200,
),
);
return on('resize', updateDimension, window);
return on('resize', updateDimension, win);
}

function wrapEventWithUserTriggeredFlag(
Expand Down Expand Up @@ -1035,6 +1036,7 @@ function initMediaInteractionObserver({
blockSelector,
mirror,
sampling,
doc,
}: observerParam): listenerHandler {
const handler = callbackWrapper((type: MediaInteractions) =>
throttle(
Expand All @@ -1061,11 +1063,11 @@ function initMediaInteractionObserver({
),
);
const handlers = [
on('play', handler(MediaInteractions.Play)),
on('pause', handler(MediaInteractions.Pause)),
on('seeked', handler(MediaInteractions.Seeked)),
on('volumechange', handler(MediaInteractions.VolumeChange)),
on('ratechange', handler(MediaInteractions.RateChange)),
on('play', handler(MediaInteractions.Play), doc),
on('pause', handler(MediaInteractions.Pause), doc),
on('seeked', handler(MediaInteractions.Seeked), doc),
on('volumechange', handler(MediaInteractions.VolumeChange), doc),
on('ratechange', handler(MediaInteractions.RateChange), doc),
];
return callbackWrapper(() => {
handlers.forEach((h) => h());
Expand Down Expand Up @@ -1279,7 +1281,9 @@ export function initObservers(
const mousemoveHandler = initMoveObserver(o);
const mouseInteractionHandler = initMouseInteractionObserver(o);
const scrollHandler = initScrollObserver(o);
const viewportResizeHandler = initViewportResizeObserver(o);
const viewportResizeHandler = initViewportResizeObserver(o, {
win: currentWindow,
});
const inputHandler = initInputObserver(o);
const mediaInteractionHandler = initMediaInteractionObserver(o);

Expand Down