electron: [Bug]: React devtools doesn't attach to devtools on launch, reload needed
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 a bug report that matches the one I want to file, without success.
Electron Version
29.1.4
What operating system are you using?
Windows
Operating System Version
Windows 11 Home 23H2
What arch are you using?
x64
Last Known Working Electron version
No response
Expected Behavior
When I launch my Electron app on developer mode, React Devtools are installed and attached to my app.
Actual Behavior
React Devtools are installed, but not attached to my app. A manual reload or force reload is required to attach it. Same problem if I installed React Devtools manually from Chrome extensions, have to reload manually.
Testcase Gist URL
No response
Additional Information
My code :
// Import required modules
const { default: installExtension, REACT_DEVELOPER_TOOLS } = require('electron-devtools-installer');
const path = require('path');
const { app, BrowserWindow } = require('electron');
// Initialize mainWindow variable
let mainWindow;
// Function to create the main window
const createWindow = async () => {
const isDev = await import('electron-is-dev');
// Configure the main window
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true, // Enable Node.js integration
enableRemoteModule: true, // Enable remote module
contextIsolation: false, // Disable context isolation
autoHideMenuBar: true, // Auto-hide menu bar
devTools: isDev.default, // Show DevTools in development
},
});
// Hide the menu bar
mainWindow.setMenuBarVisibility(true);
// Load the appropriate URL based on the environment
mainWindow.loadURL(
isDev.default
? 'http://localhost:3000' // Development URL
: `file://${path.join(__dirname, '../build/index.html')}` // Production URL
);
};
// Create the main window when the app is ready
app.whenReady().then(() => {
installExtension(REACT_DEVELOPER_TOOLS, { loadExtensionOptions: { allowFileAccess: true }})
.then((name) => {
console.log(`Added Extension: ${name}`);
// Create the window and the React application
createWindow();
})
.catch((err) => console.log('An error occurred: ', err));
});
// Quit the app when all windows are closed (except on macOS)
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
// Create a new window when the app is activated (macOS)
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
I tried also reloading the window on my code or adding a timer to reload the window but without success.
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 10
- Comments: 22 (8 by maintainers)
Commits related to this issue
- Skip Electron tests for now Looks like they're still working through stuff in https://github.com/electron/electron/issues/41613 — committed to reduxjs/redux-devtools by Methuselah96 2 years ago
- Upgrade to Manifest V3 (#1714) * Update Chrome manifest.json * Remove use of window in background * Test devpanel * Inject pageScript using new API * Keep connection from devpanel to back... — committed to reduxjs/redux-devtools by Methuselah96 2 years ago
This issue occurs because react developer tool’s content script attempts to communicate with the background service worker, which isn’t running on startup (after the first install).
A fix in Electron will likely be needed to launch these service workers upon startup. For now, you can upgrade to Electron v35 and use the following workaround:
Unfortunately, this is still happening.
Electron does not call
extensions::ProcessManager::MaybeCreateStartupBackgroundHostswhich is why the service worker neither starts nor invokes thechrome.runtime.onStartuplistener.This method can only be called once which works well for Chrome, but might not be best for Electron. I’ll think about how this can be addressed within Electron.
@SantiagoChiappe are you getting an error similar to this (reported in https://github.com/electron/electron/issues/37876#issuecomment-1984873828) in your main process?
After a bit of suffering and building like 20 different devtools versions, i’ve determined that https://github.com/facebook/react/commit/f7181993133a89b54f93d79d199be3392e5af6fc broke it on initial load. Not sure quite why yet, but there’s a good lead now.
Resolved this by using the
react-devtoolspackage instead of installing the chrome extension.yarn add --dev react-devtools"dev:react-devtools": "react-devtools"or something like that to the scripts in the package.json<script src="http://localhost:8097"></script>to the dev version of your renderer index html fileyarn run dev:react-devtoolsit will launch the react-devtools server and make the react devtools available in the app window devtools.@Stanzilla No extra info needed. As far as I know, @samuelmaddock is working on it.
It’s workable on my project. Thanks.
Exact same issue but with Vue devtools with the exception that it will not load even after reloading. Same error when trying to open devtools.
Reloading the extensions with
session.defaultSession.loadExtension(path)after some delay seems to work(1sright after the.installExtension([ext])call).Some thing like this(got hint form here)
Here are the changes for working DevTools installation: https://github.com/usebruno/bruno/pull/3750/files#diff-f4f68ad80b8c2edfa98747336270c25acbc51531460feadd6bf496ca3314f854R55-R70
Without the reload with delay, the behavior seems inconsistent
.loadExtensionwithout delay and never without it.still repro on electron v33 with v4 of the installer. creating one here: https://github.com/electron/electron/issues/45128
React Devtools not even attaching after refresh on my end, I’m unable to get it working at all. This is with Electron v33.3.0. I’m on Ubuntu x86.
Here’s the code I’m using to load the extension:
Relevant output (same as above):