After updating my Electron app from Electron 8.2.5 to 9.0.0, the following errors start to appear in the terminal:
[1] (electron) 'BrowserWindow.addDevToolsExtension' is deprecated and will be removed. Please use 'session.loadExtension' instead.
[1] Added Extension: [object Object]
[1] (electron) 'BrowserWindow.getDevToolsExtensions' is deprecated and will be removed. Please use 'session.getAllExtensions' instead.
[1] Added Extension: [object Object]
My electron app uses electron-devtools-installer
to install React Developer Tools and Redux DevTools after the Electron app has loaded.
How can we make use of session.loadExtension
and session.getAllExtensions
to install devtools properly in Electron 9?
const electron = require("electron");
const app = electron.app;
const path = require("path");
const isDev = require("electron-is-dev");
let mainWindow;
const BrowserWindow = electron.BrowserWindow;
const installExtensions = async () => {
const { default: installExtension, REACT_DEVELOPER_TOOLS, REDUX_DEVTOOLS } = require('electron-devtools-installer');
const extensions = [REACT_DEVELOPER_TOOLS, REDUX_DEVTOOLS];
for (const extension of extensions) {
try {
const name = await installExtension(extension);
console.log(`Added Extension: ${name}`);
} catch (e) {
console.log('An error occurred: ', err);
}
}
}
...
app.on("ready", async () => {
createWindow();
if (isDev) {
await installExtensions();
mainWindow.webContents.on("did-frame-finish-load", () => {
mainWindow.webContents.once("devtools-opened", () => {
mainWindow.focus();
});
mainWindow.webContents.openDevTools({
mode: 'undocked'
});
});
}
});