Skip to content

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

Open

Description

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.
  • [BUG] caret parameter for expect.toHaveScreenshot with forcedColors: 'active' and colorScheme dark does not work.  #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

Activity

  1. microsoft-playwright-automation commented on Nov 10, 2026

    @microsoft-playwright-automation
  2. microsoft-playwright-automation commented on Nov 10, 2026

    @microsoft-playwright-automation
    Contributor

    Hi, I'm the Playwright bot. I reproduced this and checked it without Playwright.

    This is a Chromium regression. It reproduces in Playwright 1.65.0 and current 1.66.0-next (c6405a9ebcf74fba1db96a5e358c7462348fbd3e), both using Chromium 158.0.8127.18. Playwright 1.64.0 with Chromium 156.0.8078.4 works. Chromium's Page.captureScreenshot with captureBeyondViewport: true changes the text from white to black while the forced-colors media query stays active. The same commands reproduce it without importing or launching through Playwright.

    In my minimal page, the background remains black rather than turning white, but the white text disappears from the full-page image and later viewport images. Firefox and WebKit retain their initial rendering.

    Reproduction and results

    I extended the existing EM-010 should emulate forcedColors test with this case:

    await page.emulateMedia({ colorScheme: 'dark', forcedColors: 'active' });
    await page.setContent('<p>Text</p><div style="height:3000px"></div>');
    const color = () => page.evaluate(() => getComputedStyle(document.body).color);
    const initialColor = await color();
    await page.screenshot();
    expect(await color()).toBe(initialColor);
    await page.screenshot({ fullPage: true });
    expect(await page.evaluate(() => matchMedia('(forced-colors: active)').matches)).toBe(true);
    expect(await color()).toBe(initialColor); // Chromium: black instead of white.

    All runs were on Linux (Ubuntu 24.04), not the reported Jammy container.

    Playwright Browser Mode Result
    1.58.2 Chromium 145.0.7632.6 Headless Page and tall-element captures preserve white text
    1.64.0 Chromium 156.0.8078.4 Headless Page and tall-element captures preserve white text
    1.65.0 Chromium 158.0.8127.18 Headless Both captures change text to black
    1.66.0-next, commit above Chromium 158.0.8127.18 Headless Both captures change text to black
    Same current commit Chromium 158.0.8127.18 Headed Full-page capture changes text to black
    Same current commit Firefox 159.0 Headless Initial text color survives full-page capture
    Same current commit WebKit 27.2 Headless Initial text color survives full-page capture

    For each published-version comparison, I checked a viewport capture, two large captures, and a later viewport capture. In 1.65.0 and current Chromium, image pixels also confirm the loss of white text, starting with the first large capture. I tested locator('body').screenshot() for the tall-element case, not toHaveScreenshot().

    Reapplying page.emulateMedia({ colorScheme: 'dark', forcedColors: 'active' }) restores the page's text color. It does not repair the image already captured.

    The linked #15211 concerns caret hiding, not this capture-induced change.

    Upstream Chromium report: reproduction without Playwright

    Title: Page.captureScreenshot(captureBeyondViewport=true) loses forced-colors text rendering and leaves the page in that state

    Affected: Chromium 158.0.8127.18, revision 6449d9f9a6a906edff724b7b220199b3fde4615c, Linux.

    Known good: Chromium 156.0.8078.4. The identical direct CDP sequence preserves white text there.

    Launch Chromium with --headless --remote-debugging-port=0 and a fresh user-data directory. Connect a CDP client and send these commands to a page target:

    await send('Page.enable');
    await send('Emulation.setDeviceMetricsOverride', {
      width: 1280, height: 720, deviceScaleFactor: 1, mobile: false
    });
    const media = { features: [
      { name: 'prefers-color-scheme', value: 'dark' },
      { name: 'forced-colors', value: 'active' }
    ] };
    await send('Emulation.setEmulatedMedia', media);
    await send('Runtime.evaluate', {
      expression: `document.body.innerHTML = '<p>Text</p><div style="height:3000px"></div>'`
    });
    const state = {
      expression: `JSON.stringify({
        color: getComputedStyle(document.body).color,
        forced: matchMedia('(forced-colors: active)').matches
      })`
    };
    await send('Runtime.evaluate', state); // white, forced=true
    await send('Page.captureScreenshot', {
      format: 'png', captureBeyondViewport: false,
      clip: { x: 0, y: 0, width: 1280, height: 720, scale: 1 }
    });
    await send('Runtime.evaluate', state); // still white, forced=true
    await send('Page.captureScreenshot', {
      format: 'png', captureBeyondViewport: true,
      clip: { x: 0, y: 0, width: 1280, height: 3032, scale: 1 }
    });
    await send('Runtime.evaluate', state); // BUG: black, forced=true
    await send('Emulation.setEmulatedMedia', media);
    await send('Runtime.evaluate', state); // white again, forced=true

    Expected: capture preserves both the rendered forced colors and the page's state. Actual: full-page capture loses the white text, and subsequent viewport captures remain wrong.

    The reproduction uses only browser-process launch and CDP commands; no Playwright screenshot preparation, CSS injection, or cleanup is involved. The fix belongs in Chromium's screenshot/emulation handling. This report is ready for a maintainer to file at https://crbug.com/new; this run cannot file Chromium issues.

    Triaged on Linux by the Playwright bot - agent run

  3. pavelfeldman commented on Nov 10, 2026

    @pavelfeldman
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions