[Feature]: Support compression effort option for WebP screenshots and visual regression

未关闭
#43,045 2 条评论 2 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 1 天内回复

@yury-s 已经在做这个了。

开始于 2026年10月5日。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
55/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
活跃
技术栈
typescript, wasm
领域
testing-qa

调研方向

Start by tracing WebP encoding for page.screenshot(), locator.screenshot(), and expect(page).toHaveScreenshot(), including the playwright.config.ts expect settings and bundled libwebp WASM module. Done means all listed APIs accept an integer effort from 0 to 6 with a default of 0, and lossless screenshots remain pixel-identical while supporting the requested compression setting.

由索引模型根据 Issue 内容生成。

描述

milestone
🚀 Feature Request

Add an effort option (integer from 0 to 6, defaulting to 0) for WebP screenshots across:

  • page.screenshot()

  • locator.screenshot()

  • expect(page).toHaveScreenshot()

    • Per assertion
    • Via playwright.config.ts
Example
playwright.config.ts
import { defineConfig } from '@playwright/test';

export default defineConfig({
  expect: {
    toHaveScreenshot: {
      type: 'webp',
      effort: 4, // Baseline snapshots encoded with method 4
    },
  },
});
Per screenshot / assertion
// Direct screenshot
await page.screenshot({
  path: 'snapshot.webp',
  type: 'webp',
  effort: 6,
});

// Visual regression
await expect(page).toHaveScreenshot('landing.webp', {
  effort: 4,
});
Motivation

WebP is already supported in Playwright for both direct screenshots and visual regression snapshots (toHaveScreenshot()). Lossless WebP snapshots can provide 20–30%+ file size reductions compared to PNG.

In libwebp, the compression effort (method, range 0–6) controls how intensively the encoder searches for spatial and entropy redundancies.

Because the compression is strictly lossless:

  • effort: 0 and effort: 6 produce 100% pixel-identical RGBA buffers.
  • effort: 0 encodes quickly with minimal CPU usage, making it suitable for test-run screenshots and comparisons.
  • effort: 4–6 can significantly reduce file size, making it suitable for baseline/golden files committed to Git repositories.

Currently, Playwright's bundled libwebp WASM module does not expose the method parameter.

Adding this option would allow users to:

  1. Store smaller WebP baseline snapshots in their repositories and reduce repository bloat.
  2. Keep CI runs fast by generating comparison screenshots with effort: 0 while validating against high-effort baselines with zero pixel difference.
主要语言
TypeScript
星标
100k
派生
6.9k
平均合并
16 小时 8 分钟
30 天内合并 PR
281

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/playwright 的其他 Issue

查看 microsoft/playwright 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。