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 in Java by Nicholas
• 7,120 points

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 in Java by Rahul
• 3,380 points
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 in Java by Damonlang
• 700 points
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 in Java by Damonlang
• 300 points
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
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
0 votes
2 answers

How to read the files using Java?

You can use collections. try (Stream<Path> filePathStream=Files.walk(Paths.get("/home/you/Desktop"))) { ...READ MORE

answered Jul 10, 2018 in Java by Sushmita
• 6,900 points
0 votes
0 answers

Chrome extension HTML Tree Generator is not working

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

Jul 27 in HTML by Tejashwini
• 2,860 points
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 in Java by Aditya
• 7,660 points
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 in HTML by Ashwini
• 2,760 points
0 votes
1 answer

Violation Long running JavaScript task took xx ms

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

answered Nov 15 in Java by Damonlang
• 300 points
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP