Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Fix issue where only indication I could see in any attribute that the…
… document was scrolling was on `window.pageYOffset`, so we hadn't been able to replay scrolling
  • Loading branch information
eoghanmurray committed Nov 17, 2022
commit d6055c5d88c06dec1917de9d506b228740d3559b
18 changes: 2 additions & 16 deletions packages/rrweb/src/record/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
on,
getWindowWidth,
getWindowHeight,
getWindowScroll,
polyfill,
hasShadowRoot,
isSerializedIframe,
Expand Down Expand Up @@ -379,22 +380,7 @@ function record<T = eventWithTime>(
type: EventType.FullSnapshot,
data: {
node,
initialOffset: {
left:
window.pageXOffset !== undefined
? window.pageXOffset
: document?.documentElement.scrollLeft ||
document?.body?.parentElement?.scrollLeft ||
document?.body?.scrollLeft ||
0,
top:
window.pageYOffset !== undefined
? window.pageYOffset
: document?.documentElement.scrollTop ||
document?.body?.parentElement?.scrollTop ||
document?.body?.scrollTop ||
0,
},
initialOffset: getWindowScroll(window),
},
}),
);
Expand Down
7 changes: 4 additions & 3 deletions packages/rrweb/src/record/observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
throttle,
on,
hookSetter,
getWindowScroll,
getWindowHeight,
getWindowWidth,
isBlocked,
Expand Down Expand Up @@ -280,11 +281,11 @@ export function initScrollObserver({
}
const id = mirror.getId(target as Node);
if (target === doc) {
const scrollEl = (doc.scrollingElement || doc.documentElement)!;
const scrollLeftTop = getWindowScroll(doc.defaultView);
scrollCb({
id,
x: scrollEl.scrollLeft,
y: scrollEl.scrollTop,
x: scrollLeftTop.left,
y: scrollLeftTop.top,
});
} else {
scrollCb({
Expand Down
22 changes: 22 additions & 0 deletions packages/rrweb/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,28 @@ export function patch(
}
}

export function getWindowScroll(win): number {
const doc = win.document;
return {
left:
doc.scrollingElement ? doc.scrollingElement.scrollLeft
: win.pageXOffset !== undefined
? win.pageXOffset
: doc?.documentElement.scrollLeft ||
doc?.body?.parentElement?.scrollLeft ||
doc?.body?.scrollLeft ||
0,
top:
doc.scrollingElement ? doc.scrollingElement.scrollTop
: win.pageYOffset !== undefined
? win.pageYOffset
: doc?.documentElement.scrollTop ||
doc?.body?.parentElement?.scrollTop ||
doc?.body?.scrollTop ||
0,
}
}

export function getWindowHeight(): number {
return (
window.innerHeight ||
Expand Down