question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

feat: emulate prefers-color-scheme

See original GitHub issue

It 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:closed
  • Created 4 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
tomayaccommented, Sep 5, 2019

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

{
  …
  userPreferences: {
    "prefers-color-scheme": 'dark',
    "prefers-reduced-motion": 'reduce',
  }
  …
}

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.

0reactions
manucorporatcommented, Dec 11, 2019

Seems like this issue was shipped with page.emulateMedia()!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found