How to detect enable-force-dark flag on Chrome v78 using JavaScript

0 votes

I just developed and implemented a dark mode for my website that employs bespoke dark colours to complement the light (default) colour scheme, and I also recently discovered that Chrome 78 includes an optional feature called #enable-force-dark. When enabled (the user must do so), Chrome will attempt to convert websites to a dark theme. It does so independently of the OS's preference, which means that a user can set light mode system-wide yet Chrome would still convert with this flag enabled.

As mentioned in previous forums, I'm using the following code to determine whether or not a user's device likes dark mode. It's worth noting that I'm detecting it using javascript since there's a button that toggles it back and forth, and it eventually ended up being a bug.

if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
    // my dark mode code goes here
}

This if statement is included within a jQuery $(window).load method and works flawlessly.


What I need is the ability to detect Chrome's new #enable-force-dark setting, reverse the modifications Chrome performs, and enable my own instead, because the Chrome conversion is incomplete and messes up my own styles. I'm conscious that this functionality isn't generally used, but I'd like to be prepared for the future.

Is this in any way possible? I don't need to ask the user to disable that flag, although if necessary I will. Thank you!

Nov 17, 2022 in Java by Nicholas
• 7,760 points
503 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Java

0 votes
0 answers

How to decode jwt token in javascript without using a library?

How can I decode the payload of ...READ MORE

Apr 21, 2022 in Java by Rahul
• 3,380 points
1,587 views
0 votes
1 answer

How to decode jwt token in javascript without using a library?

Working unicode text JWT parser function: function parseJwt ...READ MORE

answered Nov 4, 2022 in Java by Damonlang
• 700 points
7,398 views
0 votes
1 answer

How to draw a circle in HTML5 Canvas using JavaScript?

Here's how to draw a circle in ...READ MORE

answered Nov 15, 2022 in Java by Damonlang
• 1,230 points
968 views
0 votes
0 answers

How to get the current London time and date using javascript

Using the code below, I attempted to& ...READ MORE

Dec 7, 2022 in Java by Nicholas
• 7,760 points
1,191 views
0 votes
1 answer

Is it possible to run a java program from command line on windows?How?

  Let's say your file is in C:\myprogram\ Run ...READ MORE

answered Apr 18, 2018 in Java by sophia
• 1,400 points
2,721 views
0 votes
3 answers

How to read input from Console using Scanner Class?

A simple example: import java.util.Scanner; public class Expl { ...READ MORE

answered Aug 1, 2018 in Java by samarth295
• 2,220 points
5,259 views
0 votes
0 answers

Chrome extension HTML Tree Generator is not working

I installed HTML Tree Generator to observe ...READ MORE

Jul 27, 2022 in HTML by Tejashwini
• 3,820 points
1,319 views
0 votes
1 answer

Cannot open local file - Chrome: Not allowed to load local resource

To answer your query, start with opening ...READ MORE

answered Feb 18, 2022 in Java by Aditya
• 7,680 points
9,042 views
0 votes
0 answers

How to re-enable right click so that I can inspect HTML elements in Chrome?

I am currently seeing a web page ...READ MORE

Jul 21, 2022 in HTML by Ashwini
• 5,430 points
729 views
0 votes
1 answer

Violation Long running JavaScript task took xx ms

These messages are classified as warnings rather ...READ MORE

answered Nov 15, 2022 in Java by Damonlang
• 1,230 points
4,286 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP