Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Failed to load React Devtools #36545

Closed
3 tasks done
Tracked by #1012
sprout2000 opened this issue Dec 3, 2022 · 57 comments · Fixed by #40500
Closed
3 tasks done
Tracked by #1012

[Bug]: Failed to load React Devtools #36545

sprout2000 opened this issue Dec 3, 2022 · 57 comments · Fixed by #40500
Assignees
Labels
22-x-y 23-x-y bug 🪲 component/devtools status/confirmed A maintainer reproduced the bug or agreed with the feature

Comments

@sprout2000
Copy link

sprout2000 commented Dec 3, 2022

Preflight Checklist

Electron Version

22.0.0

What operating system are you using?

macOS

Operating System Version

macOS Monterey 12.6

What arch are you using?

arm64 (including Apple Silicon)

Last Known Working Electron version

No response

Expected Behavior

I want to load React Devtools whose manifest version is v3.

app.whenReady().then(async () => {
  new BrowserWindow().loadFile("index.html");

  const devtoolPath = path.join(
    os.homedir(),
    "/Library/Application Support/Google/Chrome/Default/Extensions/fmkadmapgofadopljbjfkapdkoienihi/4.27.0_0"
  );
  await session.defaultSession.loadExtension(devtoolPath, {
    allowFileAccess: true,
  });
});

2022-12-03-152048

Actual Behavior

Received an error message "Permission 'scripting' is unknown or URL pattern is malformed":

(node:44297) ExtensionLoadWarning: Warnings loading extension at $HOME/Library/Application Support/Google/Chrome/Default/Extensions/fmkadmapgofadopljbjfkapdkoienihi/4.27.0_0:
  Permission 'scripting' is unknown or URL pattern is malformed.

Stack Trace

[44297:1203/150155.162121:ERROR:extensions_browser_client.cc(62)] Extension Error:
  OTR:     false
  Level:   1
  Source:  manifest.json
  Message: Service worker registration failed. Status code: 15
  ID:      fmkadmapgofadopljbjfkapdkoienihi
  Type:    ManifestError
[44297:1203/150155.162205:ERROR:extensions_browser_client.cc(62)] Extension Error:
  OTR:     false
  Level:   2
  Source:  chrome-extension://fmkadmapgofadopljbjfkapdkoienihi/build/background.js
  Message: Uncaught TypeError: Cannot read properties of undefined (reading 'registerContentScripts')
  ID:      fmkadmapgofadopljbjfkapdkoienihi
  Type:    RuntimeError
  Context: chrome-extension://fmkadmapgofadopljbjfkapdkoienihi/build/background.js
  Stack Trace: 
    {
      Line:     107
      Column:   1
      URL:      chrome-extension://fmkadmapgofadopljbjfkapdkoienihi/build/background.js
      Function: (anonymous function)
    }

Testcase Gist URL

No response

Additional Information

The problem has not occurred with Vue3 devtools, whose manifest version is v2.

2022-12-03-152723

@sprout2000 sprout2000 changed the title [Bug]: Fails to load React Devtools with "allowFileAccess: true" [Bug]: Fails to load React Devtools Dec 3, 2022
@sprout2000 sprout2000 changed the title [Bug]: Fails to load React Devtools [Bug]: Failed to load React Devtools Dec 3, 2022
@Kilian
Copy link
Member

Kilian commented Dec 7, 2022

Ran into this too. 4.27 switched over to manifest v3 which could be the cause, but according to facebook/react#25145 they also now use chrome.scripting.registerContentScripts which is an API electron might not support yet.

edit: yes, chrome.scripting isn't implemented: MarshallOfSound/electron-devtools-installer#232

@Kilian
Copy link
Member

Kilian commented Dec 13, 2022

I wrote up some quick downgrade instructions for Electron apps (replace "Polypane" with your app name): https://polypane.app/docs/downgrading-react-devtools/

@codebytere
Copy link
Member

Closing as an upstream bug: facebook/react#25843

@codebytere codebytere closed this as not planned Won't fix, can't repro, duplicate, stale Jan 4, 2023
@mondaychen
Copy link

@codebytere Can you please reopen this? I believe Electron should add chrome.scripting APIs (as well as other Manifest V3 support) to fix this issue.
Here's my argument facebook/react#25843 (comment)

@spamshaker
Copy link

how to disable this warning?

@nostazac
Copy link

nostazac commented Apr 3, 2023

Errror is in this line
$HOME/Library/Application Support/Google/Chrome/Default/Extensions/fmkadmapgofadopljbjfkapdkoienihi/4.27.0_0.

The warning specifically mentions that the permission "scripting" is unknown or the URL pattern is malformed. This could indicate that the extension is using a deprecated or outdated permission, or that the URL patterns specified in the extension manifest are incorrect.

To address this issue, you could try disabling or removing the extension causing the warning and see if the problem persists. Alternatively, you could contact the developer of the extension for further assistance in resolving the issue.

@sprout2000
Copy link
Author

Still same with Electron v24.x.

[26821:0415/145134.612606:ERROR:extensions_browser_client.cc(67)] Extension Error:
  OTR:     false
  Level:   2
  Source:  chrome-extension://fmkadmapgofadopljbjfkapdkoienihi/build/background.js
  Message: Uncaught TypeError: Cannot read properties of undefined (reading 'registerContentScripts')
  ID:      fmkadmapgofadopljbjfkapdkoienihi
  Type:    RuntimeError
  Context: chrome-extension://fmkadmapgofadopljbjfkapdkoienihi/build/background.js
  Stack Trace: 
    {
      Line:     107
      Column:   1
      URL:      chrome-extension://fmkadmapgofadopljbjfkapdkoienihi/build/background.js
      Function: (anonymous function)
    }
[26821:0415/145134.612901:ERROR:extensions_browser_client.cc(67)] Extension Error:
  OTR:     false
  Level:   1
  Source:  manifest.json
  Message: Service worker registration failed. Status code: 15
  ID:      fmkadmapgofadopljbjfkapdkoienihi
  Type:    ManifestError
[26821:0415/145134.981682:ERROR:CONSOLE(1)] "Uncaught (in promise) TypeError: Failed to fetch", source: devtools://devtools/bundled/panels/elements/elements.js (1)
[26821:0415/145135.087366:ERROR:CONSOLE(2)] "Electron sandboxed_renderer.bundle.js script failed to run", source: node:electron/js2c/sandbox_bundle (2)
[26821:0415/145135.087392:ERROR:CONSOLE(2)] "TypeError: object null is not iterable (cannot read property Symbol(Symbol.iterator))", source: node:electron/js2c/sandbox_bundle (2)

@guozhengzhongGit
Copy link

yeah
image
the latest version electron also have same error

@Vn-ChemGio
Copy link

I have same issue with electron 24.x

@sprout2000
Copy link
Author

@danielweck
The tree can be displayed, although the notation is strange since it is after bundling. But only for execution with Fiddle.

スクリーンショット 2023-10-10 18 15 22

@sprout2000
Copy link
Author

sprout2000 commented Oct 11, 2023

How to reproduce the problems I have:

  1. Clone electron-quick-start
  2. Edit main.js
  3. Run the app
% git clone https://github.com/electron/electron-quick-start.git
% cd electron-quick-start
% npm install    # v26.3.0
const { app, session, BrowserWindow } = require("electron");
const os = require("node:os");
const path = require("node:path");

app.whenReady().then(async () => {
  const mainWindow = new BrowserWindow();

  const extPath = path.join(
    os.homedir(),
    // Rewrite the Devtools version number accordingly
    "/Library/Application Support/Google/Chrome/Default/Extensions/fmkadmapgofadopljbjfkapdkoienihi/4.28.4_0"
    // on Windows
    // "/AppData/Local/Google/Chrome/User Data/Default/Extensions/fmkadmapgofadopljbjfkapdkoienihi/4.28.4_0"
  );
  await session.defaultSession.loadExtension(extPath, {
    allowFileAccess: true,
  });

  await mainWindow.loadURL("https://react.dev");
  mainWindow.webContents.openDevTools();
});

app.once("window-all-closed", () => app.quit());
% npm start

> electron-quick-start@1.0.0 start
> electron .

[12932:1013/112709.120:ERROR:extensions_browser_client.cc(69)] Extension Error:
  OTR:     false
  Level:   2
  Source:
  Message: Error handling response: TypeError: Cannot read properties of undefined (reading 'setIcon')
    at setExtensionIconAndPopup (chrome-extension://fmkadmapgofadopljbjfkapdkoienihi/build/background.js:1:1614)
    at checkAndHandleRestrictedPageIfSo (chrome-extension://fmkadmapgofadopljbjfkapdkoienihi/build/background.js:1:2090)
    at Array.forEach (<anonymous>)
    at chrome-extension://fmkadmapgofadopljbjfkapdkoienihi/build/background.js:1:2146
  ID:      fmkadmapgofadopljbjfkapdkoienihi
  Type:    RuntimeError
  Context:
  Stack Trace:
    {
      Line:     0
      Column:   1
      URL:
      Function: (anonymous function)
    }
[12932:1013/112710.544:ERROR:CONSOLE(2)] "Electron sandboxed_renderer.bundle.js script failed to run", source: node:electron/js2c/sandbox_bundle (2)
[12932:1013/112710.544:ERROR:CONSOLE(2)] "TypeError: object null is not iterable (cannot read property Symbol(Symbol.iterator))", source: node:electron/js2c/sandbox_bundle (2)
  • Does ANYONE have any problems loading the React Developer Tools with the code above?
  • Why is there a problem with the above code when there is no problem with Fiddle?

@UndefinedOffset
Copy link

UndefinedOffset commented Oct 12, 2023

It seems based on my testing using the default Electron Fiddle (adding in a simple react app) on 25.9.0, 26.3.0 and 27.0.0 the latest React Dev Tools will not load when using mainWindow.loadFile() even if you have allowFileAccess: true unless you are using a url like https://react.dev as has been used in examples above.

const { app, BrowserWindow, session } = require('electron')
const path = require('path')

async function createWindow () {
  const extPath = "{extension path}";
  await session.defaultSession.loadExtension(extPath, {
    allowFileAccess: true,
  });
  // Create the browser window.
  const mainWindow = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      preload: path.join(__dirname, 'preload.js')
    }
  })

  mainWindow.loadFile('index.html')

  mainWindow.webContents.openDevTools()
}

app.whenReady().then(() => {
  createWindow()

  app.on('activate', function () {
    if (BrowserWindow.getAllWindows().length === 0) createWindow()
  })
})

app.on('window-all-closed', function () {
  if (process.platform !== 'darwin') app.quit()
})

@Nantris
Copy link
Contributor

Nantris commented Oct 13, 2023

Now I'm even getting errors like:

proxy.js:116 Uncaught Error: Attempting to use a disconnected port object
    at handleMessageFromPage (proxy.js:116:10)

image

Very frustrating that this is only getting more and more unusable even after years of struggles to get React Devtools working in Electron. Ever since the security upgrades, particularly contextBridge it's been impossible to keep React Devtools working, and now it even interrupts work when you've given up hope on using it.

@codebytere
Copy link
Member

codebytere commented Oct 15, 2023

@UndefinedOffset can you explain a little more what you mean in #36545 (comment)? The way React Devtools works is that it does not show up on pages not containing any react components, so on a bare-bones html page it wouldn't show up by design.

@slapbox can you tell me a little more about what's breaking? I'm happy to look into it and have devoted some recent cycles to stabilizing it as can be seen in the above list of PRs.

@UndefinedOffset
Copy link

UndefinedOffset commented Oct 16, 2023

@codebytere Perhaps this will help it's very very basic just React's hello world demo https://github.com/webbuilders-group/electron-issue-36545. I also tried just using https://github.com/electron-react-boilerplate/electron-react-boilerplate and experienced the same thing the extension is not showing the dev tools after updating electron to 26.4.0. It seems to be an issue with the file:// whether you use the BrowserWindow.loadFile or BrowserWindow.loadURL. If you load https://react.dev in Electron the tools work fine. In both cases the extension is loaded using allowFileAccess: true but it doesn't appear to work.

@Nantris
Copy link
Contributor

Nantris commented Oct 17, 2023

Thanks for your reply @codebytere. We just recently started getting this issue where the debugger pauses on an uncaught exception on that line. I'm guessing there was some change in React Devtools to cause this but I don't know. It seems specific to the Electron environment but it may not be an Electron issue per se.

Our longer term problem has been that running the production app over a secure protocol prevents using the React Profiler with internal production builds, which is where it's intended to be used. #26812

@n-gist
Copy link

n-gist commented Oct 26, 2023

Can't get last DevTools (v. 4.28.5) working with Electron 27.0.2
When I replace extension files to other versions (4.25.0 or 4.27.1), it loads and works normally, but they are manifest 2 old versions.
using allowFileAccess or not gives no effect
using https://react.dev instead of local file url - no effect

Gives no errors, session.defaultSession.loadExtension resolves normally, but DevTools loaded is regular one with a message in console Download the React DevTools for a better development experience

@sprout2000
Copy link
Author

Could you please reopen this issue? The problem still remains.

スクリーンショット 2023-11-13 16 52 37

The following is a reproduced code based on electron-quick-start:

const { app, BrowserWindow, session } = require("electron");
const os = require("node:os");
const path = require("node:path");

function createWindow() {
  const mainWindow = new BrowserWindow();

  mainWindow.loadURL("https://react.dev");
  mainWindow.webContents.openDevTools();
}

const reactDevtoolsPath = path.join(
  os.homedir(),
  "/Library/Application Support/Google/Chrome/Default/Extensions/fmkadmapgofadopljbjfkapdkoienihi/4.28.5_0"
);

app.whenReady().then(async () => {
  createWindow();
  await session.defaultSession.loadExtension(reactDevtoolsPath);
});

app.once("window-all-closed", () => app.quit());

I wonder if anyone else could run the above code as is and still have React Devtools load correctly.

@zhouzi
Copy link

zhouzi commented Nov 13, 2023

The PR was merged 4 hours ago and the last release is 5 days old so the fix has not been released yet.

@sprout2000
Copy link
Author

@zhouzi
Oh... Sorry for the haste.

@zhouzi
Copy link

zhouzi commented Nov 16, 2023

This fix is now released with v26.6.0, v27.1.0 and v28.0.0-beta.5 (it's still not working for me but it might be related to my setup).

@derekcicerone
Copy link

Not working for us either.

@Bartel-C8
Copy link

Not working here either on v27.1.0 on macos:

┏ Electron -------------------

  (node:48091) ExtensionLoadWarning: Warnings loading extension at /Users/bartel/git/klstr-ctrl/node_modules/electron-devtools-vendor/extensions/react-developer-tools:
    Permission '<all_urls>' is unknown or URL pattern is malformed.
  
  (Use `Electron --trace-warnings ...` to show where the warning was created)

┗ ----------------------------
┏ Electron -------------------

  [48091:1116/135717.525208:ERROR:extensions_browser_client.cc(69)] Extension Error:
    OTR:     false
    Level:   1
    Source:  manifest.json
    Message: Service worker registration failed. Status code: 15
    ID:      dmcmnlnmbgdfljfjniabngbfglcgggdk
    Type:    ManifestError

┗ ----------------------------
┏ Electron -------------------

  [48091:1116/135717.528034:ERROR:extensions_browser_client.cc(69)] Extension Error:
    OTR:     false
    Level:   2
    Source:  chrome-extension://dmcmnlnmbgdfljfjniabngbfglcgggdk/build/background.js
    Message: Uncaught TypeError: Cannot read properties of undefined (reading 'registerContentScripts')
    ID:      dmcmnlnmbgdfljfjniabngbfglcgggdk
    Type:    RuntimeError
    Context: chrome-extension://dmcmnlnmbgdfljfjniabngbfglcgggdk/build/background.js
    Stack Trace: 
      {
        Line:     107
        Column:   1
        URL:      chrome-extension://dmcmnlnmbgdfljfjniabngbfglcgggdk/build/background.js
        Function: (anonymous function)
      }

┗ ----------------------------

Other extension (not React devtools)

┏ Electron -------------------

  [48091:1116/140148.092777:ERROR:CONSOLE(2)] "TypeError: Cannot read properties of undefined (reading 'action')", source: chrome-extension://lmhkpmbekcpmknklioeibfkpmmfibljd/window.bundle.js (2)
  [48091:1116/140148.092907:ERROR:CONSOLE(2)] "Uncaught TypeError: Cannot read properties of undefined (reading 'action')", source: chrome-extension://lmhkpmbekcpmknklioeibfkpmmfibljd/window.bundle.js (2)

┗ ----------------------------

Should we do anything special to use the chrome API? Seems that no chrome API is working...
I am using https://github.com/BlackHole1/electron-devtools-vendor to load/install my extensions....

@JStrummer
Copy link

JStrummer commented Nov 16, 2023 via email

@sprout2000
Copy link
Author

Still doesn't work on v27.1.0. What's wrong with my set up?

const { app, session, BrowserWindow } = require("electron");
const path = require("node:path");
const os = require("node:os");

function createWindow() {
  const mainWindow = new BrowserWindow();
  mainWindow.loadURL("https://react.dev");
}

const reactDevtoolsPath = path.join(
  os.homedir(),
  "/Library/Application Support/Google/Chrome/Default/Extensions/fmkadmapgofadopljbjfkapdkoienihi/4.28.5_0"
);

app.whenReady().then(async () => {
  createWindow();
  await session.defaultSession.loadExtension(reactDevtoolsPath);
});

app.once("window-all-closed", () => app.quit());
(node:14579) ExtensionLoadWarning: Warnings loading extension at /Users/doe/Library/Application Support/Google/Chrome/Default/Extensions/fmkadmapgofadopljbjfkapdkoienihi/4.28.5_0:
  Manifest contains a differential_fingerprint key that will be overridden on extension update.

@julianmesa-gitkraken
Copy link

@sprout2000

Still doesn't work on v27.1.0. What's wrong with my set up?

You forgot: , {allowFileAccess: true}
it is: await session.defaultSession.loadExtension(reactDevtoolsPath, {allowFileAccess: true});

But it is not working for me I cannot see react devtools tabs.

@julianmesa-gitkraken
Copy link

julianmesa-gitkraken commented Nov 17, 2023

@sprout2000 I think I've found a workaround.
Try to load the extension twice.

const { app, session, BrowserWindow } = require("electron");
const path = require("node:path");
const os = require("node:os");

async function createWindow() {
  const mainWindow = new BrowserWindow();
  await mainWindow.loadURL("https://react.dev");
}

const reactDevtoolsPath = path.join(
  os.homedir(),
  "/Library/Application Support/Google/Chrome/Default/Extensions/fmkadmapgofadopljbjfkapdkoienihi/4.28.5_0"
);

app.whenReady().then(async () => {
  // WARNING extension has to be loaded before create the window
  await session.defaultSession.loadExtension(reactDevtoolsPath, {allowFileAccess: true});
  await session.defaultSession.loadExtension(reactDevtoolsPath, {allowFileAccess: true});
  await createWindow();
});

app.once("window-all-closed", () => app.quit());

Now the extension works but I can see the next errors in console:

[76463:1117/150926.611076:ERROR:extensions_browser_client.cc(69)] Extension Error:
  OTR:     false
  Level:   2
  Source:  
  Message: Error handling response: TypeError: Cannot read properties of undefined (reading 'setIcon')
    at background_setExtensionIconAndPopup (chrome-extension://neodanbiabbklolgaljcmnjamjoipdcl/build/background.js:1:1158)
    at checkAndHandleRestrictedPageIfSo (chrome-extension://neodanbiabbklolgaljcmnjamjoipdcl/build/background.js:1:1542)
    at Array.forEach (<anonymous>)
    at chrome-extension://neodanbiabbklolgaljcmnjamjoipdcl/build/background.js:1:1779
  ID:      neodanbiabbklolgaljcmnjamjoipdcl
  Type:    RuntimeError
  Context: 
  Stack Trace: 
    {
      Line:     0
      Column:   1
      URL:      
      Function: (anonymous function)
    }
[76463:1117/150926.822800:ERROR:extensions_browser_client.cc(69)] Extension Error:
  OTR:     false
  Level:   2
  Source:  
  Message: Error in event handler: TypeError: Cannot read properties of undefined (reading 'setIcon')
    at background_setExtensionIconAndPopup (chrome-extension://neodanbiabbklolgaljcmnjamjoipdcl/build/background.js:1:1158)
    at chrome-extension://neodanbiabbklolgaljcmnjamjoipdcl/build/background.js:1:5018
    at chrome-extension://neodanbiabbklolgaljcmnjamjoipdcl/build/background.js:1:5081
  ID:      neodanbiabbklolgaljcmnjamjoipdcl
  Type:    RuntimeError
  Context: 
  Stack Trace: 
    {
      Line:     0
      Column:   1
      URL:      
      Function: (anonymous function)
    }
[76463:1117/150926.914557:ERROR:extensions_browser_client.cc(69)] Extension Error:
  OTR:     false
  Level:   2
  Source:  
  Message: Error in event handler: TypeError: Cannot read properties of undefined (reading 'setIcon')
    at background_setExtensionIconAndPopup (chrome-extension://neodanbiabbklolgaljcmnjamjoipdcl/build/background.js:1:1158)
    at chrome-extension://neodanbiabbklolgaljcmnjamjoipdcl/build/background.js:1:5018
    at chrome-extension://neodanbiabbklolgaljcmnjamjoipdcl/build/background.js:1:5081
  ID:      neodanbiabbklolgaljcmnjamjoipdcl
  Type:    RuntimeError
  Context: 
  Stack Trace: 
    {
      Line:     0
      Column:   1
      URL:      
      Function: (anonymous function)
    }
[76463:1117/150927.489984:ERROR:CONSOLE(2)] "Electron sandboxed_renderer.bundle.js script failed to run", source: node:electron/js2c/sandbox_bundle (2)
[76463:1117/150927.490031:ERROR:CONSOLE(2)] "TypeError: object null is not iterable (cannot read property Symbol(Symbol.iterator))", source: node:electron/js2c/sandbox_bundle (2)

@Bartel-C8
Copy link

Not able to get it working, even with the latest React Devtools...

Reproduction case in most simple form in Electron Fiddle (you can load the gist in Electron Fiddle): https://gist.github.com/Bartel-C8/0330843ddf220d8bddb64183acd7bcad

@codebytere : Would it be possible to re-open this issue? As it definitely does not seem resolved...

(node:7320) ExtensionLoadWarning: Warnings loading extension at /private/var/folders/_n/ln9pzc1s23z_619h7h6jv6d80000gn/T/electron-fiddle-4848-3ZIIKHaMCTZb/node_modules/electron-devtools-vendor/extensions/react-developer-tools:
  Permission '<all_urls>' is unknown or URL pattern is malformed.

(Use `Electron --trace-warnings ...` to show where the warning was created)
[7320:1122/093428.129424:ERROR:extensions_browser_client.cc(69)] Extension Error:
  OTR:     false
  Level:   2
  Source:  chrome-extension://cjmlfkgkjjjlokhimplkmlegcbflodei/build/background.js
  Message: Uncaught TypeError: Cannot read properties of undefined (reading 'ExecutionWorld')
  ID:      cjmlfkgkjjjlokhimplkmlegcbflodei
  Type:    RuntimeError
  Context: chrome-extension://cjmlfkgkjjjlokhimplkmlegcbflodei/build/background.js
  Stack Trace: 
    {
      Line:     1
      Column:   1
      URL:      chrome-extension://cjmlfkgkjjjlokhimplkmlegcbflodei/build/background.js
      Function: (anonymous function)
    }

[7320:1122/093428.129629:ERROR:extensions_browser_client.cc(69)] Extension Error:
  OTR:     false
  Level:   1
  Source:  manifest.json
  Message: Service worker registration failed. Status code: 15
  ID:      cjmlfkgkjjjlokhimplkmlegcbflodei
  Type:    ManifestError

[7320:1122/093428.622529:ERROR:CONSOLE(2)] "Electron sandboxed_renderer.bundle.js script failed to run", source: node:electron/js2c/sandbox_bundle (2)
[7320:1122/093428.622587:ERROR:CONSOLE(2)] "TypeError: object null is not iterable (cannot read property Symbol(Symbol.iterator))", source: node:electron/js2c/sandbox_bundle (2)

@julianmesa-gitkraken
Copy link

julianmesa-gitkraken commented Nov 22, 2023

@Bartel-C8 Can you try to load extension twice and load the extension before create createWindow?
I have extension errors but the extension works fine.

app.whenReady().then(() => {
  installExtensions()
  installExtensions()

  createWindow()

  app.on('activate', function () {
    // On macOS it's common to re-create a window in the app when the
    // dock icon is clicked and there are no other windows open.
    if (BrowserWindow.getAllWindows().length === 0) createWindow()
  })
})

Also you are using mainWindow.loadFile('index.html'), that index.html has no react.
I recommmend the next test: mainWindow.loadURL('https://react.dev');

@Bartel-C8
Copy link

@Bartel-C8 Can you try to load extension twice and load the extension before create createWindow? I have extension errors but the extension works fine.

app.whenReady().then(() => {
  installExtensions()
  installExtensions()

  createWindow()

  app.on('activate', function () {
    // On macOS it's common to re-create a window in the app when the
    // dock icon is clicked and there are no other windows open.
    if (BrowserWindow.getAllWindows().length === 0) createWindow()
  })
})

Does not work for me (macOS) with Electron Fiddle unfortunately. Does making this change in my gist work for you? Very strange...

Also you are using mainWindow.loadFile('index.html'), that index.html has no react. I recommmend the next test: mainWindow.loadURL('https://react.dev');

Same with loading [react.dev ](https://react.dev) , no React Devtools. And that should not matter normally, the React Devtools tab in the devtools should be available anyway.

@n-gist
Copy link

n-gist commented Nov 22, 2023

Double loading worked for me. Does not give me any errors though
Windows, electron 27.1.0, DevTools 4.28.5

const devToolsPath = 'D:/Users/username/AppData/Roaming/appname/extensions/fmkadmapgofadopljbjfkapdkoienihi'
const load2 = () => {
    session.defaultSession.loadExtension(devToolsPath).then(
        () => { createWindow() },
        () => {}
    )
}
const load1 = () => {
    session.defaultSession.loadExtension(devToolsPath).then(
        () => { load2() },
        () => {}
    )
}

let started = false
const start = () => {
    if (started) return
    started = true
    load1()
}

app.whenReady().then(() => {
    start()
    app.on('activate', () => start())
}).catch(console.log)

@Bartel-C8
Copy link

Bartel-C8 commented Nov 24, 2023

Got it fixed in my case, somehow the sources of my react devtools plugin provides had some issues in the manifest.json file, where "scripting" lacked under "permissions".

BlackHole1/electron-devtools-vendor#35 (comment)

Manually extracting the react-devtools to another location works!
Sorry to bother! Thanks for your work on this @codebytere !

EDIT 5.0: It appears that the latest react-devtools (4.28.5) is NOT working with local files in Electron. By coincidence I tried 4.27.0, and that one is still working fine with local files...

Not sure whether it's electron or the plugin's bug...
Loading with a local file broke somewhere betweem 4.27.3 and 4.27.6 ... Trying to pinpoint the exact version where it broke, but I need to manually rebuild this. As the CRX's are not available here: https://www.crx4chrome.com/history/3068/

EDIT bis: Breaks between 4.27.4 (works) and 4.27.5 (doesn't work)

EDIT bis2: It DOES work with 4.28.5, but indeed, somehow I need to load it "twice", but just loading it twice in code is not enough in my case (macos). I need to "close" the application with the red cross "X" and re-click the app in the dock. This creates a new window instance. And thereafter the devtools show up. I guess it's a react (devtools) issue. So will report there!

Only workaround that (programatically) let it work on "first time" (kinda hacky)
(let createWindow return the created mainWindow )

  await installExtensions()

  let win = createWindow()

  win.webContents.on("did-finish-load", () => {
    console.log("load ======================================================")
    win.close()
    win = createWindow()
  })

@alperen-bircak
Copy link

Still doesn't work for me, I get the same errors, does not work with double loading as well.

@rendomnet
Copy link

This is not WORKING!

@Bartel-C8
Copy link

Do try my workaround above, or vote for the new issue:

As this is a react devtools issue now, not related to electron...

facebook/react#27749

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
22-x-y 23-x-y bug 🪲 component/devtools status/confirmed A maintainer reproduced the bug or agreed with the feature
Projects
No open projects
Status: Unsorted Issues
Development

Successfully merging a pull request may close this issue.