Skip to content

Commit 212552f

Browse files
Erik Bendersindresorhus
andauthored
Add support for new session extension handling in Electron 9 (sindresorhus#80)
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
1 parent 29b58de commit 212552f

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

index.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
const {app, BrowserWindow} = require('electron');
2+
const {app, BrowserWindow, session} = require('electron');
33
const localShortcut = require('electron-localshortcut');
44
const isDev = require('electron-is-dev');
55

@@ -54,13 +54,25 @@ function inspectElements() {
5454

5555
const addExtensionIfInstalled = (name, getPath) => {
5656
const isExtensionInstalled = name => {
57+
// For Electron >=9.
58+
if (session.defaultSession.getAllExtensions) {
59+
return {}.hasOwnProperty.call(session.defaultSession.getAllExtensions(), name);
60+
}
61+
62+
// TODO: Remove this when targeting Electron >=9.
5763
return BrowserWindow.getDevToolsExtensions &&
5864
{}.hasOwnProperty.call(BrowserWindow.getDevToolsExtensions(), name);
5965
};
6066

6167
try {
6268
if (!isExtensionInstalled(name)) {
63-
BrowserWindow.addDevToolsExtension(getPath(name));
69+
// For Electron >=9.
70+
if (session.defaultSession.loadExtension) {
71+
session.defaultSession.loadExtension(getPath(name));
72+
} else {
73+
// TODO: Remove this when targeting Electron >=9.
74+
BrowserWindow.addDevToolsExtension(getPath(name));
75+
}
6476
}
6577
} catch (_) {}
6678
};

0 commit comments

Comments
 (0)