[Bug]: Full-page screenshots in Chromium lose forcedColors: 'active' rendering, and the page doesn't recover

オープン
#44,041 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
52/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
playwright, typescript

調査の方向性

The reproduction uses page.screenshot() and expect(locator).toHaveScreenshot() with Chromium and forced colors; the report points to Page.captureScreenshot with captureBeyondViewport: true. Start by tracing full-page screenshot capture and forced-colors emulation in Chromium. Reproduce with the provided test in the Playwright 1.65.0 Chromium project; done means full-page captures preserve forced-colors rendering and the page remains in that rendering afterward.

索引モデルが issue の本文から書いたものです。

説明

cr-bug initiative
Version

1.65.0

Steps to reproduce
import { expect, test } from '@playwright/test'

test.use({ colorScheme: 'dark', forcedColors: 'active' })

test('forced colors survive a full-page screenshot', async ({ page }) => {
  await page.setContent('<p>Text</p><div style="height: 3000px"></div>')

  const bodyColor = () => page.evaluate(() => getComputedStyle(document.body).color)

  expect(await bodyColor()).toBe('rgb(255, 255, 255)')

  await page.screenshot()
  expect(await bodyColor()).toBe('rgb(255, 255, 255)')

  await page.screenshot({ fullPage: true })
  expect(await bodyColor()).toBe('rgb(255, 255, 255)')
})

Run with the Chromium project in mcr.microsoft.com/playwright:v1.65.0-jammy.

Expected behavior

The page keeps forced-colours rendering after every screenshot, and the full-page screenshot is drawn with forced colours.

Actual behavior
  • The viewport screenshot is fine.
  • The full-page screenshot comes out without forced colours: normal colours on a white background.
  • After it, the page stays out of forced-colours rendering. Body text is rgb(0, 0, 0) instead of rgb(255, 255, 255), and later viewport screenshots are wrong too.
  • matchMedia('(forced-colors: active)').matches still returns true throughout. Only the rendering is lost, not the media query.

The same thing happens with expect(locator).toHaveScreenshot() when the element is taller than the viewport. That's how we found it: all our high-contrast visual regression snapshots came out in light mode after upgrading.

Additional context
  • It seems to happen whenever Playwright sends Page.captureScreenshot with captureBeyondViewport: true (when the capture doesn't fit the viewport). Screenshots that fit the viewport are unaffected.
  • The screenshot code (captureBeyondViewport: !fitsViewport) and the media emulation code look the same in 1.58.2 and 1.65.0. Our snapshots rendered correctly with 1.58.2 (Chromium 145), which suggests a change in Chromium rather than in Playwright.
  • Emulation works correctly without the full-page capture, with either forcedColors set directly or contextOptions: { forcedColors: 'active' }. PLAYWRIGHT_LEGACY_SCREENSHOT=1 makes no difference to a viewport-sized capture. We haven't tried it with a full-page capture.
  • We haven't tested Firefox, WebKit, or Playwright 1.64.
  • #15211 is a different bug, but is in a similar area.
Environment
- Operating System: Ubuntu 22.04 (mcr.microsoft.com/playwright:v1.65.0-jammy)
- Browser: Chrome Headless Shell 158.0.8127.18
- @playwright/test: 1.65.0
主要言語
TypeScript
スター
100k
フォーク
6.9k
平均マージ
16時間 8分
マージ済み PR(30日)
281

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microsoft/playwright のほかの issue

microsoft/playwright の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。