Our visual tests started failing on a Monday after nobody had touched the app. Forty screenshot comparisons differed by a few pixels around text and form controls. The cause was a dependency bump in the test tooling that switched the headless browser from one implementation to the other. Both were called "headless Chrome", both were the same Chrome version, and they did not produce identical pixels.
If you run Chrome without a window in CI, for tests, screenshots or PDFs, you now have to choose between two products. This post explains what they are, how Puppeteer and Playwright pick one, and how to pin your choice so upgrades are deliberate.
A short history
Until 2023,
--headlesslaunched a separate implementation: a lightweight browser shell built on Chrome's content layer, sharing the rendering engine but not the full browser code. It behaved differently from headed Chrome in many small ways.Chrome 112 added a new headless mode, enabled with
--headless=new. It is the real Chrome browser with the window simply not shown, so it behaves like the Chrome your users run.Chrome 120 onward, the old implementation was published separately as
chrome-headless-shellthrough Chrome for Testing.Chrome 132 removed the old mode from the Chrome binary. Since then,
--headlessand--headless=newboth mean the new mode, and the old implementation exists only aschrome-headless-shell.
What each one is good at
New headless (Chrome) | chrome-headless-shell | |
|---|---|---|
Code base | Full Chrome browser | Minimal shell on Chrome's content layer |
Fidelity to real Chrome | Matches headed Chrome closely | Small behaviour and rendering differences |
Startup and memory | Heavier | Lighter, faster to start |
Browser features | Most browser features, including those that live outside the content layer | Only what the shell implements |
| Not supported | Supported with |
Typical use | End-to-end tests, anything that must match users | High-volume screenshots, PDFs, scraping where cost matters |
The practical rule: if a test is supposed to prove that something works in Chrome, use the new headless mode. If you render thousands of pages and only need consistent output, the shell is cheaper.
How Puppeteer chooses
Since Puppeteer 22, the headless launch option has three values:
await puppeteer.launch({ headless: true }); // new headless mode in Chrome (default)
await puppeteer.launch({ headless: 'shell' }); // chrome-headless-shell
await puppeteer.launch({ headless: false }); // headed
Puppeteer downloads Chrome for Testing builds that match the library version. You can install a specific browser yourself with the @puppeteer/browsers CLI:
npx @puppeteer/browsers install chrome@stable
npx @puppeteer/browsers install chrome-headless-shell@stable
How Playwright chooses
Playwright downloads its own Chromium builds. Since Playwright 1.49:
Headless runs with the default
chromiumbrowser usechromium-headless-shell.Setting
channel: 'chromium'opts into the new headless mode of the full Chromium build.Setting
channel: 'chrome'or'msedge'uses the branded browser installed on the machine, in its new headless mode.
// playwright.config.ts
import { defineConfig, devices } from '@playwright/test';
export default defineConfig({
projects: [
{
name: 'chromium-e2e',
use: { ...devices['Desktop Chrome'], channel: 'chromium' }, // new headless
},
],
});
To keep CI images small, Playwright can install only what you use:
npx playwright install --with-deps --only-shell chromium # headless shell only
npx playwright install --with-deps --no-shell chromium # full Chromium only
Why screenshots change between the two
The shell and full Chrome share Blink and Skia, but not every code path. In our failing tests the differences were:
form controls (checkboxes, selects, scrollbars) drawn slightly differently;
small text anti-aliasing differences on some fonts;
default window and screen sizes that differed when the test did not set a viewport.
We confirmed this by running the same test twice on the same commit, once with each implementation, and diffing the screenshots: every failing image differed only in these areas. None of these are bugs in your app. They are reasons why a baseline captured with one implementation should never be compared with the other.
What to pin in CI
Pin the implementation explicitly
Do not rely on the library's default. Write the mode into config so a library upgrade cannot switch it silently:
// puppeteer: be explicit even when it matches the default
const browser = await puppeteer.launch({ headless: true });
// playwright: name the channel for e2e projects
use: { channel: 'chromium' }
Pin the browser version
With Puppeteer, the browser version is tied to the Puppeteer version. Pin Puppeteer exactly in your lockfile and upgrade it on purpose.
With Playwright, the same applies to the
@playwright/testversion. If you usechannel: 'chrome', the version comes from whatever Chrome is installed on the runner, so install a fixed version in your CI image instead of the system's latest.Build the CI image once with the browser inside it, tag it, and use the tag. Runners that download browsers on every job can pick up a new build in the middle of a release.
Keep baselines per implementation
If you run both modes (for example, the shell for a fast smoke suite and new headless for the full suite), store screenshot baselines separately, named by project. Playwright does this automatically when you use projects; with other tools, include the mode in the baseline path.
Upgrade on a branch
Treat a browser upgrade like a dependency upgrade:
Bump the library on a branch.
Run the visual suite and review every diff.
Update baselines in the same pull request, with the browser version in the commit message.
Quick check: what am I running?
Log the browser version and launch arguments at the start of every CI run:
const browser = await puppeteer.launch({ headless: true });
console.log(await browser.version());
console.log(browser.process()?.spawnargs.join(' '));
// Playwright
console.log(browser.browserType().name(), browser.version());
If the executable path contains chrome-headless-shell, you are on the shell. When a visual test fails "for no reason", this line is the first thing to compare with the last green run.
Common mistakes
Mistake | Why it hurts | Do this instead |
|---|---|---|
Relying on the default headless mode | Library upgrades switch implementations | Set the mode explicitly in config |
Sharing baselines across modes | Pixel diffs on every run | One baseline set per mode and browser version |
Using the system Chrome in CI | Version changes with runner images | Bake a fixed browser into a tagged CI image |
Passing | Ignored by Chrome 132 and later | Use |
Using the shell for e2e sign-off | Behaviour can differ from real Chrome | Use new headless for tests that prove user flows |
Key takeaways
"Headless Chrome" is now two products: new headless inside Chrome, and
chrome-headless-shell.New headless matches real Chrome; the shell is lighter and faster but not identical.
Puppeteer uses new headless by default (
headless: 'shell'for the shell); Playwright uses the shell by default and new headless withchannel: 'chromium'.Pin the mode, pin the browser version, and keep separate baselines.
Log the browser version and executable path in every CI run.
References
Chrome developers, Chrome headless mode: https://developer.chrome.com/docs/chromium/headless
Chrome developers, chrome-headless-shell: https://developer.chrome.com/blog/chrome-headless-shell
Chrome for Testing: https://developer.chrome.com/blog/chrome-for-testing
Puppeteer, headless modes: https://pptr.dev/guides/headless-modes
Playwright, browsers and headless shell: https://playwright.dev/docs/browsers
Comments
0No comments yet. Be the first to comment!
Sign In to post a comment.