diff --git a/aio/src/app/shared/scroll.service.ts b/aio/src/app/shared/scroll.service.ts index ab5f299b66e7c..57dc5a77ec53b 100644 --- a/aio/src/app/shared/scroll.service.ts +++ b/aio/src/app/shared/scroll.service.ts @@ -24,7 +24,7 @@ export class ScrollService implements OnDestroy { poppedStateScrollPosition: ScrollPosition|null = null; // Whether the browser supports the necessary features for manual scroll restoration. supportManualScrollRestoration: boolean = !!window && ('scrollTo' in window) && - ('scrollX' in window) && ('scrollY' in window) && isScrollRestorationWritable(); + ('pageXOffset' in window) && ('pageYOffset' in window) && isScrollRestorationWritable(); // Offset from the top of the document to bottom of any static elements // at the top (e.g. toolbar) + some margin diff --git a/packages/common/src/viewport_scroller.ts b/packages/common/src/viewport_scroller.ts index a7c9093426938..5becb84f7c1ef 100644 --- a/packages/common/src/viewport_scroller.ts +++ b/packages/common/src/viewport_scroller.ts @@ -89,7 +89,7 @@ export class BrowserViewportScroller implements ViewportScroller { */ getScrollPosition(): [number, number] { if (this.supportsScrolling()) { - return [this.window.scrollX, this.window.scrollY]; + return [this.window.pageXOffset, this.window.pageYOffset]; } else { return [0, 0]; } @@ -149,7 +149,7 @@ export class BrowserViewportScroller implements ViewportScroller { */ private supportScrollRestoration(): boolean { try { - if (!this.window || !this.window.scrollTo) { + if (!this.supportsScrolling()) { return false; } // The `scrollRestoration` property could be on the `history` instance or its prototype. @@ -166,7 +166,8 @@ export class BrowserViewportScroller implements ViewportScroller { private supportsScrolling(): boolean { try { - return !!this.window.scrollTo; + return !!this.window && !!this.window.scrollTo && !!this.window.pageXOffset && + !!this.window.pageYOffset; } catch { return false; }