feat: emulate prefers-color-scheme
See original GitHub issueIt would be interesting to simulate different values of prefers-color-scheme
, so developers could write visual tests for light and dark mode.
Possible API:
page.emulate({
viewport: {
colorScheme: 'dark'
}
});
There is an article of how this could be achieved: https://www.bram.us/2019/09/04/take-both-light-and-dark-mode-screenshots-with-puppeteer/
But seems rather hacky and unperformant, since it needs to boot up two completely different chrome instances.
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
How can I emulate prefers-color-scheme media query in ...
Press F12 key (or Command+Shift+C on Mac); Click on the tree dots symbol (customize and control DevTools); Point your mouse on the more...
Read more >prefers-color-scheme: Hello darkness, my old friend - web.dev
Debugging and testing dark mode #. Emulating prefers-color-scheme in DevTools #. Switching the entire operating system's color scheme can get ...
Read more >prefers-color-scheme media query | Can I use... Support ...
Media query to detect if the user has set their system to use a light or dark color theme. Usage % of. all...
Read more >prefers-color-scheme - CSS: Cascading Style Sheets | MDN
The prefers-color-scheme CSS media feature is used to detect if a user has requested light or dark color themes.
Read more >Dark Mode - The prefers-color-scheme Website Tutorial
TIP: You can test emulating prefers-color-scheme with Chrome DevTools (Customize and control DevTools > More tools > Rendering > Emulate CSS media feature ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Heya, @tomayac here, author of the “hacky” and “unperformant” solution https://github.com/tomayac/dark-mode-screenshot. I would very much +1 a native way in Puppeteer, as typically the flags that my approach uses at the moment tend to be rather ephemeral.
Different than the proposal above, I would, however, vouch for a more generic approach that allows for testing all current and potential future User Preference Media Features, like
prefers-reduced-motion
,prefers-contrast
etc.My idea would be to have a field where one can shove the different media features à la
I’m not that familiar with the Puppeteer API, so would leave it to the authors to decide where such a field would live best.
Seems like this issue was shipped with
page.emulateMedia()
!