diff --git a/lib/browser/chrome-extension.js b/lib/browser/chrome-extension.js index b0045294f38e..835d1b150f5b 100644 --- a/lib/browser/chrome-extension.js +++ b/lib/browser/chrome-extension.js @@ -149,10 +149,6 @@ const manifestToExtensionInfo = function (manifest) { const loadDevToolsExtensions = function (win, manifests) { if (!win.devToolsWebContents) return - for (const manifest of manifests) { - startBackgroundPages(manifest) - injectContentScripts(manifest) - } const extensionInfoArray = manifests.map(manifestToExtensionInfo) win.devToolsWebContents.executeJavaScript(`DevToolsAPI.addExtensions(${JSON.stringify(extensionInfoArray)})`) } @@ -182,20 +178,6 @@ app.on('will-quit', function () { // We can not use protocol or BrowserWindow until app is ready. app.once('ready', function () { - // Load persisted extensions. - loadedExtensionsPath = path.join(app.getPath('userData'), 'DevTools Extensions') - try { - const loadedExtensions = JSON.parse(fs.readFileSync(loadedExtensionsPath)) - if (Array.isArray(loadedExtensions)) { - // Preheat the manifest cache. - for (const srcDirectory of loadedExtensions) { - getManifestFromPath(srcDirectory) - } - } - } catch (error) { - // Ignore error - } - // The chrome-extension: can map a extension URL request to real file path. const chromeExtensionHandler = function (request, callback) { const parsed = url.parse(request.url) @@ -227,6 +209,23 @@ app.once('ready', function () { } }) + // Load persisted extensions. + loadedExtensionsPath = path.join(app.getPath('userData'), 'DevTools Extensions') + try { + const loadedExtensions = JSON.parse(fs.readFileSync(loadedExtensionsPath)) + if (Array.isArray(loadedExtensions)) { + for (const srcDirectory of loadedExtensions) { + // Start background pages and set content scripts. + const manifest = getManifestFromPath(srcDirectory) + startBackgroundPages(manifest) + injectContentScripts(manifest) + } + } + } catch (error) { + // Ignore error + } + + // The public API to add/remove extensions. BrowserWindow.addDevToolsExtension = function (srcDirectory) { const manifest = getManifestFromPath(srcDirectory) if (manifest) { @@ -245,7 +244,7 @@ app.once('ready', function () { delete manifestMap[name] } - // Load persisted extensions when devtools is opened. + // Load extensions automatically when devtools is opened. const init = BrowserWindow.prototype._init BrowserWindow.prototype._init = function () { init.call(this)