-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support website's native dark mode #1285
Comments
BTW, as the current way is quite hard, I asked Mozilla to implement an API or so for this feature: https://bugzilla.mozilla.org/show_bug.cgi?id=1547818 Please upvote, if you want this, too. |
Support for prefers-color-scheme will now be available in Chrome 76 https://blog.chromium.org/2019/06/chrome-76-beta-dark-mode-payments-new.html |
Changing the media Only thing that is needed in the extension is sending a boolean, "automatic detection" variable from the extension so it isn't turned on by default. I don't have time to work on this right now, but could take a look later on. |
Scratch that. I think we should add them to Global Dark List now regardless, since most operating systems already support them. |
Note that this isn't working yet on Linux for Chrome: https://crbug.com/998903 |
What about to add support for auto changing theme to dark or light for macOS Chrome? |
Would be cool with OS dark mode synchronisation as well, enabling/disabling dark reader based on system wide preferences. It is probably easily implemented by the proxy of "prefers-color-scheme", but at least Windows 10 (see AppsUseLightTheme, SystemUsesLightTheme) and a couple of linux desktops has flags for dark mode (see gtk-application-prefer-dark-theme...) |
Removing in the title |
This is the part that I’m after. My personal page and I guess many other small pages support dark mode and will show ugly black rectangles when the addon is activated. It would be nice to have a setting “Apply to sites that autoadapt themselves” where you could toggle between the current behavior (Forcing application on every site) vs trusting that websites with A bit tricky since there’s e.g. React sites that don’t have static CSS with that media query but instead a dynamic one: https://material-ui.com/components/use-media-query/ (all (hopefully) based on |
Edit: I totally missed that there's already a pull request for this. 🤦♂️ There's now two standard ways of doing this:
While they both technically mean something else ("please render default elements like inputs with [a particular color scheme]"), I think they can be reasonably understood to mean "this website natively supports [said color scheme]" in the vast majority of cases, so adding support for them would solve this problem for a lot of websites. If anyone's interested in how |
Awesome! So once that’s merged and my page contains |
Yep. And if the user uses prefers a dark-color scheme we won't enable Dark Reader so it will uses the site's one. While when it's detected that the user prefers a light color scheme we will still enable Dark Reader as the site will not according to this Regards, |
Hi!! Are there any updates about this? I love Dark Reader! |
These sites use dynamic theme (i.e., detect theme while allowing override):
These sites use dynamic mode, but user session is required for switching themes: |
I'm going to repeat myself, they currently aren't that reliable. "Metadata is error-prone, as long websites don't even know how to use it correctly, we shouldn't rely on it. It will cause more bad than good" - #1285 (comment)
That's how the current implementation work, we're waiting for Dark Reader to finish it's first rounds of modification which should give the browser + the site some time to do their thing and in most cases already load their dark mode(if they have any). The behavior that you observe, that dark mode is still being applied is the technical limitation of detecting a site's dark mode. We can of course simple wait for the site to load to avoid that issue, but that's not how Dark Reader works. Nobody wants to see the site's original theme, it may in this case be a annoyance because the site is already dark themed, but for non-dark themed sites it will cause a huge white flash for your eyes. |
I would be interested in why you are so sure about the fact that websites don't know how to implement the meta tag? |
Because there seems to be a misunderstanding that the meta tag's functionality actually is. As per spec: https://html.spec.whatwg.org/multipage/semantics.html#meta-color-scheme It's simply a hint to the browser to style some things(like currently the scrollbar) dark-themed. While it may also serve(only defined in example, pretty vague) that the site implements a dark mode. Btw, I'm not sure, it's just a vague thing that popped up in the HTML specifications and from my perspective hasn't a clear definition, if a big site(like google or reddit or youtube) start to only use it to say to the browser to style elements dark-themed(regardless the site's native color-scheme), the bugs about it will roll in, I have to decide if we should add a "denylist" for such sites(spoiler, I don't want more list than we currently have) or remove the feature again. It's too vague and error-prone to even consider it as a option IMO. |
I mean it does a bit more than just make the scrollbar dark. It also changes the background color and the text color of the site. In general just all default gui elements become dark including the default color scheme. (Because they use the default color scheme ...) So if you apply this meta tag, your whole website automatically becomes dark. Except you override those, then of course you could do funny things, but I would be confused about why anyone would do such a thing :D In general I don't think that there are high risks of it being misused because whenever a site sets this meta tag to dark, it gets a lot of dark styled default behaviour, which is something that the site would not want if its not a dark site, or am I missing something? |
That’s exactly how it is. @Gusted please read the standard draft more carefully, it’s all there. Il’ll use dark reader once it has a setting to reliably turn itself off on a website that claims it supports dark mode. |
That's correct, well, why would anyone not use the CSS to make your site nicer? I don't know of any single site that doesn't use CSS and let the browser decide which colors the site will use. The implementations I've seen so far, has been to get dark-styles elements(scrollbar, dropdowns, inputs etc.), we're actually abusing that fact ourselves: #8012 to get those elements dark-themed. Yet it doesn't imply that the site itself is dark, it can still override to use a light themed background color.
I'm not sure about the risks, a site simply can still set other values then it's supposed to have(according to the color-scheme), it still sounds error-prone in my ears. The elements indeed gets dark-styles default behavior, but from my own experience web developers are using it to style the native elements control but still decide most other colors(html, body etc.) which can still be light. A site's implementation can be "wrong" very easily.
We're currently already doing that, see #7995, currently we're detecting it, as not every dark site will actually use meta tags. On another note, I'm not actually quite sure why we still should support/detect the meta tag, the detection(#7995) should catch most of those site. Supporting the meta tag as well, will only increase small amount of sites and can be dangerous if the meta tag + site's CSS is "incorrect". Unless there's a sudden movement among sites to include such meta tag, I personally think it's not worth the hassle of checking for it. |
Exactly. I don’t want the detection code to run when there’s a metadata tag. I want a setting to trust it. |
I would not consider it to be an abusement to set the tag, if the rest of the site is dark. It is correct to activate the tag when a site is dark. Even if it got dark through an extension. The only thing that matters is the current state.
You keep saying that and I will keep saying that I just can't believe it to be that much of a risk as you give it credit to be. Just because it "is possible" that does not automatically mean, that people will so it, of it makes no sense at all. And activating dark styles for a website that is not dark just seems extremely weird and I just don't think people are actually doing that.
As said before, the meta tag would help very much on deciding if a site should be converted to dark mode or not "early on" this would prevent those weird rendering annoyances where the side gets first converted and then unconverted, as dark reader detects that it actually already has a dark mode. Also there are still many sites that don't work with dark reader. For example I use a CMS called directus all the time and dark reader just doesn't get its in dark mode. But the meta tag would work just fine. In general I think those decisions should not be made on a "feeling", that stuff might be misused. Maybe we should just collect some data on pages that use those tags and if they implement dark mode or not. This would give us an actual answer to the big question if this thing really actually gets misused or not. What do you think? |
Seems like a reasonable argument to add it.
This doesn't seems like related to detecting a dark mode?
Yeah, I'm not that big on data collection so that's a big no-go. I can add a secret setting somewhere in the UI so average users won't suddenly spam with bug reports why dark reader doesn't work anymore(because the risk is still there, how big it may be), because in the past adding new features which are experimental only resulted in negative things and ultimately being removed. I'm trying to prevent such new scenario's again, by only carefully adding new features which are stable for the 99.99% use-case. I will update #3902 soon to include it. |
While we're at the topic: Let's take github.com, it has the Now, this is the first time that this user actually visits github.com and decide that their color-scheme isn't that great, so it goes to github's settings and set it white, now Dark Reader hasn't a clue that the light theme is enabled and won't do anything. How would Dark Reader handle such case? Making the user again explicitly enable github.com in the popup is annoyance IMO and should be avoided and can be considered a bug by the user. |
Respect the user’s choice to explicitly choose a light theme for GitHub only. |
I personally would've expect that Dark Reader would've taken over dark theme styling(even if a refresh is needed to kick the detection). |
Can't we just scan a sites CSS and if it has any prefers-color-scheme query in it assume it respects native dark mode built in and auto-disable darkreader for it? (these are those where it usually inverts it again, creating a white background again) (And assuming it checks if prefers-color-scheme is turned on by user) Oh and Chrome on Linux has a workaround, change the Exec line your chrome.desktopfile to It's "just" missing the UI to conveniently turn it on/off like on Windows or like Firefox. |
I've tried a while ago(1.5+ years) and some major sites are quite misbehaving. Well, it's a good heuristic, it's unfortunately not a rock solid condition to check for. |
The feature was added some time ago via #7995, you need to activate it in the UI. The algorithm is improved from time to time. If you see the issues please leave a brief message with a link. |
Doesn't detect "native darkmode" at first on https://www.rockland.dk/. |
just tested: works fine for me from the first vist |
Hmm, okay. Maybe I can't find out defining the right settings. I find them a bit confusing. Thanks for the check, I will try playing around with settings a bit more. |
Why does that PR do some weird CSS calculation? All you have to do to check if a website officially supports dark mode is const colorSchemes = document.querySelector("meta[name='color-scheme']").getAttribute("content")
const supportsDarkMode = colorSchemes.split(/\s+/).includes("dark") The mentioned website https://www.rockland.dk/ defines <meta name="color-scheme" content="light dark"> there should be zero configuration or question necessary before dark reader sees that and turns itself off immediately. |
The suggestion is good and it can improve the detection. Unfortunately this meta tag is rarely used and there is still the need to check the actual colours used on the website. |
Please submit the websites where it doesn't work correctly here, as it was the earliest feature suggestion of that type #81 |
Oh, sorry, I was wrong: darkreader ignores rockland.dk's dark theme, even after page reload. Enable-disable darkreader makes it work right. |
@532910 That's alright, the meta fix works well. However I blocked Mr Philipp A. from participation in this conversation for his toxic tone. Unfortunately the previous releases are still under review for Chrome and Firefox, so I will publish this fix as soon as it passes, and we will see how it goes. |
I really really think this should be on by default. |
Firefox 67 introduced the new
prefers-color-scheme
CSS media feature. (It's not currently available for any other browsers that support browser/WebExtensions.)With that websites can detect a dark system mode and adjust their design.
It would obviously be great, if you could integrate that, somehow. And there are many possibilities.
That said, I've already tried that (to force a particular design) and it is really not a nice thing to implement. At least forcing the black design works, as this is how websites likely implement it, but anything else is likely not really possible…
So this is rather a proof-of-concept (although it works quite fine if you just want to force the websites to use their native black design.).
Test the add-on here!
Source code: https://github.com/rugk/website-dark-mode-switcher/
What is easy is:
.matchMedia
query and you know it)What is hard is:
You may also just disable this add-on on sites, where you detect it used. It opens many possibilities/ideas…
Edit: Due to new Firefox APIs the v2 of the linked extension is much more powerful and now can easily and reliably force the dark or light mode on websites.
Test sites are linked in the add-on, but here again:
The text was updated successfully, but these errors were encountered: