Skip to content

Commit 1b64783

Browse files
fix(screenshot): preserve scroll-driven animation progress (#44022)
1 parent c6405a9 commit 1b64783

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

‎packages/playwright-core/src/server/screenshotter.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ function inPagePrepareForScreenshots(screenshotStyle: string, hideCaret: boolean
112112
for (const animation of root.getAnimations()) {
113113
if (!animation.effect || animation.playbackRate === 0 || infiniteAnimationsToResume.has(animation))
114114
continue;
115+
if (!(animation.timeline instanceof DocumentTimeline))
116+
continue;
115117
const endTime = animation.effect.getComputedTiming().endTime;
116118
if (Number.isFinite(endTime)) {
117119
try {

‎tests/page/page-screenshot.spec.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,28 @@ declare global {
740740
}
741741

742742
it.describe('page screenshot animations', () => {
743+
it('SS-098 should preserve scroll animation progress during screenshots', {
744+
annotation: { type: 'issue', description: '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/microsoft/playwright/issues/43986' },
745+
}, async ({ page }) => {
746+
await page.setContent(`
747+
<style>
748+
@keyframes reveal { from { opacity: 0 } to { opacity: 1 } }
749+
body { timeline-scope: --progress; }
750+
#scroller { width: 100px; overflow-x: auto; scroll-timeline: --progress x; }
751+
#content { width: 200px; height: 20px; }
752+
#indicator { width: 40px; height: 40px; background: red;
753+
animation: reveal linear both; animation-timeline: --progress; }
754+
</style>
755+
<div id="scroller"><div id="content"></div></div>
756+
<div id="indicator"></div>
757+
`);
758+
await rafraf(page);
759+
const expected = await page.screenshot({ animations: 'allow' });
760+
const actual = await page.screenshot({ animations: 'disabled' });
761+
expect(comparePNGs(actual, expected)).toBe(null);
762+
expect((await page.screenshot({ animations: 'allow' })).equals(expected)).toBe(true);
763+
});
764+
743765
it('SS-052 should not capture infinite css animation', async ({ page, server }) => {
744766
await page.goto(server.PREFIX + '/rotate-z.html');
745767
const div = page.locator('div');

‎tests/registry.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4999,6 +4999,7 @@ subsystem, add a row to the Subsystems table. Then update this file:
49994999
| `SS-095` | `page/page-screenshot.spec.ts` | page screenshot › should capture webgl canvas after its drawing buffer is resized |
50005000
| `SS-096` | `page/page-screenshot.spec.ts` | page screenshot › should not wait for unused font face with failed local() source |
50015001
| `SS-097` | `page/page-screenshot.spec.ts` | page screenshot › should take fullPage screenshots of SVG documents |
5002+
| `SS-098` | `page/page-screenshot.spec.ts` | page screenshot animations › should preserve scroll animation progress during screenshots |
50025003

50035004
### ST — Storage
50045005

0 commit comments

Comments
 (0)