electron: Electron 6 does not launch in Win10 dark mode with DevTools extensions installed

Preflight Checklist

  • I have read the Contributing Guidelines for this project.
  • I agree to follow the Code of Conduct that this project adheres to.
  • I have searched the issue tracker for an issue that matches the one I want to file, without success.

Issue Details

  • Electron Version:
    • 6.0.0
  • Operating System:
    • Windows 10 (1903)
  • Last Known Working Electron version:
    • 6.0.0-beta.13

Expected Behavior

Electron should launch and display a window regardless of whether Windows is in Light or Dark mode.

Actual Behavior

If Windows is in Dark Mode, then Electron will hang on launch if any DevTools extension is installed.

This behaviour only occurs if a devtools extension has been installed on a previous run.

Everything is fine if Windows is in Light mode when the app is launched.

To Reproduce

UPDATED REPRO (see comment history for original version)

  1. Ensure Windows “choose your color” setting is set to “Dark”.
  2. Clone and install repro and launch Electron:
    $ git clone https://github.com/caesar/electron-darkmode-crash.git
    $ cd electron-darkmode-crash
    $ npm i
    $ npm run start
    
    The first time, Electron will launch normally.
  3. Once electron has launched, close it.
  4. Launch Electron again:
    $ npm run start
    
    The second time, Electron will hang and never display a window.

The above repro contains the following changes from electron-quick-start:master : https://github.com/caesar/electron-darkmode-crash/commit/65ab2a0bec0e4a9baca6a9cb2cbfda94817c4ae9

Additional Information

I originally thought this might be an issue with vue-cli-plugin-electron-builder and filed a bug at https://github.com/nklayman/vue-cli-plugin-electron-builder/issues/378, but that possibility has now been eliminated as simply installing Vue.js Devtools or React Devtools in a clean clone of electron-quick-start is enough to trigger the bug.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 67
  • Comments: 57 (19 by maintainers)

Commits related to this issue

Most upvoted comments

@MarshallOfSound hey there, any news from the team about this?

@caesar Because the issue only comes into play with devtools extensions it’s not serious enough to block the release. It’s definitely on the list of things to fix though.

@MarshallOfSound any news? This should be high priority

I don’t get why this painful issue isn’t yet solved. The issue is 6 month old and I believe it’s affecting a lot of people ? Is there any technical challenge hard to solve ?

This issue is still relevant in Electron 8.0.0

This issue is present in electron 7.1.10 as well.

@MarshallOfSound it’s blocking us from upgrading because of this:

This behaviour only occurs if a devtools extension has been installed on a previous run.

We sometimes use our own debug mode on customers machines, which will install devtools extensions. If a customer, or even one of our own developers, runs into this bug, there’s no easy search term given the log messages and the behavior of the app that will lead them to the “turn off dark mode” solution. It’s going to be a frustrating time. Plus, based on this thread, it sounds like the exact problem is unclear, so I’m worried this will repro in more cases than what’s listed.

I’m able to reproduce this on the latest electron version (7.1.9)

I’m facing the same problem. Now, I just write two tricky cmd script to change windows theme mode automaticly when developing.

dark.cmd

@echo off
%1 %2
mshta vbscript:createobject("shell.application").shellexecute("%~s0","goto :runas","","runas",1)(window.close)&goto :uacfalse
:runas
REG ADD HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize /v AppsUseLightTheme /t REG_DWORD /d 0 /f
goto :eof
:uacfalse

light.cmd

@echo off
%1 %2
mshta vbscript:createobject("shell.application").shellexecute("%~s0","goto :runas","","runas",1)(window.close)&goto :uacfalse
:runas
REG ADD HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize /v AppsUseLightTheme /t REG_DWORD /d 1 /f
goto :eof
:uacfalse

some “scripts” lines in my package.json:

"start-main-dev": "webpack --config webpack.main.config.js && npm run win-light && electron ./dist/main.js && npm run win-dark",
"win-light": "cd scripts && light.cmd",
 "win-dark": "cd scripts && dark.cmd"

I’m not sure if I could just change back the theme after electron started. The scripts just change the registry of the theme selection, the UAC related lines could also be removed.

Found temporary fix for this, add the following script to package.json

"dev:light": "yarn win-light && yarn dev && yarn win-dark",
"win-light": "REG ADD HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize /v AppsUseLightTheme /t REG_DWORD /d 1 /f",
"win-dark": "REG ADD HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize /v AppsUseLightTheme /t REG_DWORD /d 0 /f"

And, instead of using yarn dev command, use yarn dev:light. Basically it just switch the app theme into light without opening setting menu. Hope this help. source

Can 100% confirm this is an Electron bug now: same issue with React Devtools.

@DalderupMaurice Maybe you have to do this:

Electron remembers installed devtools, so just removing the installation which runs on every launch won’t delete the already-installed tools. The installed tools are stored in your application’s data directory which on Windows is C:\Users\[yourname]\AppData\Roaming\[appname] Delete that directory, and your app will be in a clean state with no devtools installed.

Since we updated electron we’ve been hitting the same issue. One thing I’d like to add (not sure if still relevant) is that I can get rid of the issue simply by removing the “DevToolExtensions” file which resides in the appdata/roaming folder. However, it’s created again when (re)launching, the issue only appears when launching with the file present (so if you delete the file you can start it again, one time). I’m faced with fixing this issue and I would rather not have to come up with some convoluted way to get rid of that file before startup. Anyone else has a proper workaround for this? Even catching it and showing a message would be something.

I’ve been using @wmhilton 's workaround (posted a few comments above) for a while and it works very well.

@DalderupMaurice Maybe you have to do this:

Electron remembers installed devtools, so just removing the installation which runs on every launch won’t delete the already-installed tools. The installed tools are stored in your application’s data directory which on Windows is C:\Users\[yourname]\AppData\Roaming\[appname] Delete that directory, and your app will be in a clean state with no devtools installed.

After removing the complete directory, I still wasn’t able to launch the application in both light and dark mode.

One interesting fact is that, after deleting the directory, I did manage to get it working by adjusting the start command.

First I used electron . with the main property in my package.json set to ./dist/index.js Changing the command to electron ./dist/index.js fixed the issue. I am now able to launch the application in both light and dark mode (WITHOUT devtools installed).

@MarshallOfSound just wondering, since 6.0.0 release seems to be scheduled for tomorrow – this seems like a pretty serious issue, is it considered a blocker for the release?

I unfortunately don’t have an environment capable of building Electron at the moment or I’d do more to look into this, but I guess a git bisect on the few commits between beta-13 and beta-14 would at least find where the regression was introduced…