Skip to content

Commit

Permalink
♻️ round scroll values everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
bcaudan committed Aug 3, 2022
1 parent 8dec744 commit 941d59e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions packages/rum/src/domain/record/observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ function initScrollObserver(cb: ScrollCallback, defaultPrivacyLevel: DefaultPriv
} else {
cb({
id,
x: (target as HTMLElement).scrollLeft,
y: (target as HTMLElement).scrollTop,
x: Math.round((target as HTMLElement).scrollLeft),
y: Math.round((target as HTMLElement).scrollTop),
})
}
}),
Expand Down
24 changes: 14 additions & 10 deletions packages/rum/src/domain/record/viewports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,27 @@ export const getVisualViewport = (): VisualViewportRecord['data'] => {
}

export function getScrollX() {
let scrollX
const visual = window.visualViewport
if (visual) {
return visual.pageLeft - visual.offsetLeft
}
if (window.scrollX !== undefined) {
return window.scrollX
scrollX = visual.pageLeft - visual.offsetLeft
} else if (window.scrollX !== undefined) {
scrollX = window.scrollX
} else {
scrollX = window.pageXOffset || 0
}
return window.pageXOffset || 0
return Math.round(scrollX)
}

export function getScrollY() {
let scrollY
const visual = window.visualViewport
if (visual) {
return visual.pageTop - visual.offsetTop
}
if (window.scrollY !== undefined) {
return window.scrollY
scrollY = visual.pageTop - visual.offsetTop
} else if (window.scrollY !== undefined) {
scrollY = window.scrollY
} else {
scrollY = window.pageYOffset || 0
}
return window.pageYOffset || 0
return Math.round(scrollY)
}

0 comments on commit 941d59e

Please sign in to comment.