We found the chrome flag chrome://flags/#enable-force-dark that forces all websites to use dark mode and it's quite nice actually!
We cannot get this flag to work in Electron, however. Here's what we tried:
app.commandLine.appendSwitch('enable-force-dark');
app.commandLine.appendSwitch('force-dark-mode');
app.commandLine.appendSwitch('enable-features', 'enableForceDark');
app.commandLine.appendSwitch('enable-features', 'WebUIDarkMode');
Sadly, none of them work. Any pointers would be appreciated.
Electron is a runtime for building desktop applications using web technologies. The project began at GitHub as the foundation for the Atom text editor. Electron combines the Chromium Content Module, which is a stripped-down version of the Chrome web browser with Node.
Electron supports a subset of the Chrome Extensions API, primarily to support DevTools extensions and Chromium-internal extensions, but it also happens to support some other extension capabilities.
The Electron docs specify a list of supported command line switches (some of which do come from Chromium). Unfortunately, --enable-force-dark
is not on that list.
That's because it should be:
app.commandLine.appendSwitch('enable-features', 'WebContentsForceDark');
You can find it out by enabling it and going to chrome://version
and looking at the command line.
However in this case you should use themeSource
instead.
Edit: Actually I guess that isn't the same as forcing dark mode (not sure you should do that) but if you want to I think maybe you're meant to do this instead:
new BrowserWindow({
webPreferences: {
enableBlinkFeatures: "WebContentsForceDark",
},
...
I haven't tried it though, and it seems to be hella janky. I can't make it work through any method for CSSColorSchemeUARendering
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With