Skip to content

Add --color-scheme flag for prefers-color-scheme emulation - #191

Open
duggan wants to merge 1 commit into
simonw:mainfrom
duggan:color-scheme-flag
Open

duggan wants to merge 1 commit into
simonw:mainfrom
duggan:color-scheme-flag

Conversation

@duggan

@duggan duggan commented Feb 27, 2026 •

Copy link
Copy Markdown

Hey @simonw, thanks for shot-scraper! Found it through your post about showboat (sidenote: the showboat README has a broken link to shot-scraper that should be pointing to https://github.com/simonw/shot-scraper rather than https://github.com/shot-scraper).

I've steered Claude to add a flag for dark mode / light mode, as it makes things simpler than trying to wrangle the Javascript via the args. Have used it in one of my own projects to create alternate light and dark illustrative screenshots depending on what the user has selected.

Dropping the PR for it here in case you find it useful.

Add a new --color-scheme [light|dark|no-preference] option to the shot, multi, and javascript commands, allowing emulation of the prefers-color-scheme CSS media feature via Playwright's color_scheme browser context option.


📚 Documentation preview 📚: https://shot-scraper--191.org.readthedocs.build/en/191/

Add a new --color-scheme [light|dark|no-preference] option to the shot,
multi, and javascript commands, allowing emulation of the
prefers-color-scheme CSS media feature via Playwright's color_scheme
browser context option.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Packetslave

Copy link
Copy Markdown

Independent confirmation that this fills a real gap — with evidence that there's no user-side workaround, which I think is the part that makes this worth having in core.

I needed exactly this today and first tried to get it without patching shot-scraper (1.11). There's no way to do it:

  • --browser-arg doesn't work. Tested against a fixture that sets a CSS custom property to LIGHT, overridden to DARK under @media (prefers-color-scheme: dark):

    shot-scraper javascript fixture.html \
      "getComputedStyle(document.documentElement).getPropertyValue('--tag')" \
      --browser-arg="--blink-settings=preferredColorScheme=0"
    "\"LIGHT\""
    

    preferredColorScheme=1 returns "LIGHT" as well.

  • --javascript can't reach it. prefers-color-scheme is a browser-level media feature; page JS can't change what the CSS engine matches against.

  • --force-dark-mode isn't a substitute. It synthesises a dark theme by inverting a light page, so it never exercises the site's authored dark CSS — usually the exact thing you're trying to screenshot.

That leaves CDP Emulation.setEmulatedMedia, which is what Playwright's color_scheme context option drives — so mirroring the existing reduced_motion handling, as this PR does, looks like the right shape.

One scope note for anyone finding this later: #121 also asks for per-shot keys in the multi YAML. This PR adds the flag at the command level, so it applies uniformly across a run rather than letting one file capture light and dark variants. Still useful on its own, and the two are separable.

(Heads up that this currently shows as conflicting against main.)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants