You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{test,expect}from'@playwright/test';test('has light theme if no preference',async({page})=>{awaitpage.emulateMedia({colorScheme: 'no-preference'});constdark=awaitpage.evaluate(()=>window.matchMedia('(prefers-color-scheme:dark)').matches);console.debug('dark: ',dark);awaitexpect(dark).toEqual(false);});
I believe it's expected to have a consistent color preference in any browser, even if no-preference color scheme is set explicitly for the test.
Actual behavior
If dark theme preference is set in macOS, but the test sets no-preference color scheme, it still falls back to the system and chooses the dark one instead of light.
Additional context
Here's a short log example when you run the test code snippet from above:
[chromium] › theme.spec.ts:3:1 › has light theme if no preference
dark: false
[firefox] › theme.spec.ts:3:1 › has light theme if no preference
dark: false
[webkit] › theme.spec.ts:3:1 › has light theme if no preference
dark: true
Alright, we've looked into it more. no-preference was part of an earlier version of the color schemes CSS spec, but was never implemented broadly. Safari initially added support, but then removed it. I've opened an issue with MDN to update it there.
I'll add a note about this to the Playwright docs.
This also means that what you're seeing is the intended behaviour: Browsers don't know what "no-preference" is, so they fall back to the system setting.
Version
1.47.2
Steps to reproduce
Here's a minimal reproduction test:
Here's real-life example:
satelllte/space • tests-e2e/theme.spec.ts
Expected behavior
I believe it's expected to have a consistent color preference in any browser, even if
no-preference
color scheme is set explicitly for the test.Actual behavior
If dark theme preference is set in macOS, but the test sets
no-preference
color scheme, it still falls back to the system and chooses the dark one instead of light.Additional context
Here's a short log example when you run the test code snippet from above:
Environment
The text was updated successfully, but these errors were encountered: