diff --git a/src/server/snapshot/snapshotterInjected.ts b/src/server/snapshot/snapshotterInjected.ts index 526cce8ddd..46dcd10f60 100644 --- a/src/server/snapshot/snapshotterInjected.ts +++ b/src/server/snapshot/snapshotterInjected.ts @@ -322,19 +322,15 @@ export function frameSnapshotStreamer(snapshotStreamer: string) { attrs['checked'] = ''; } } - if (element === document.scrollingElement) { - // TODO: restoring scroll positions of all elements - // is somewhat expensive. Figure this out. - if (element.scrollTop) { - expectValue(kScrollTopAttribute); - expectValue(element.scrollTop); - attrs[kScrollTopAttribute] = '' + element.scrollTop; - } - if (element.scrollLeft) { - expectValue(kScrollLeftAttribute); - expectValue(element.scrollLeft); - attrs[kScrollLeftAttribute] = '' + element.scrollLeft; - } + if (element.scrollTop) { + expectValue(kScrollTopAttribute); + expectValue(element.scrollTop); + attrs[kScrollTopAttribute] = '' + element.scrollTop; + } + if (element.scrollLeft) { + expectValue(kScrollLeftAttribute); + expectValue(element.scrollLeft); + attrs[kScrollLeftAttribute] = '' + element.scrollLeft; } if (element.shadowRoot) { ++shadowDomNesting; diff --git a/tests/snapshotter.spec.ts b/tests/snapshotter.spec.ts index 0063f75767..87837731d0 100644 --- a/tests/snapshotter.spec.ts +++ b/tests/snapshotter.spec.ts @@ -237,6 +237,45 @@ it.describe('snapshots', () => { expect(divColor).toBe('rgb(0, 0, 255)'); await previewContext.close(); }); + + it('should restore scroll positions', async ({ page, contextFactory, toImpl, snapshotter, snapshotPort, browserName }) => { + it.skip(browserName === 'firefox'); + + await page.setContent(` + +